Variables in shell script not working

Carl Friis-Hansen ubuntuuser at carl-fh.com
Sat Nov 15 14:00:45 UTC 2008


Jef Driesen wrote:
> 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'
> 
> 

You forgot the *cat* command in your script.

-- 
       +---------------------------------+-------------------+
       | Carl Friis-Hansen               | Fiskeryd Nybygget |
       | http://computingconfidence.com/ | 341 91  Ljungby   |
       | Phone: +46 (0)372 15033         | Sweden            |
       +---------------------------------+-------------------+





More information about the ubuntu-users mailing list