Variables in shell script not working

Jef Driesen jefdriesen at hotmail.com
Sat Nov 15 13:40:57 UTC 2008


Karl Auer wrote:
> On Sat, 2008-11-15 at 14:16 +0100, Jef Driesen wrote:
>> if [ -n "$FILENAME" ]
>> then
>>     SOURCE=dos2unix "$FILENAME"
>> else
>>     SOURCE=dos2unix
>> fi
> 
> You need to wrap the variable value in quotes if it contains a space.
> 
>    SOURCE="dos2unix $FILENAME"
> 
> Here's a mini script, test, to show you:
> 
>    X=that
>    Y="this $X"
>    echo $Y
> 
> Run it (sh test) and you will get the correct output:
> 
>    this that
> 
> Take the double quotes out, and you'll see:
> 
>    test: 2: that: not found

If I quote the variable, the error disappears, but the rest of my script 
does not work anymore. No output is produced on stdout. Echo'ing the 
variable works, but the script does not seem to execute the contents of 
the variable when it reaches the line

$SOURCE | sed 's/foo/bar'





More information about the ubuntu-users mailing list