Variables in shell script not working

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


Karl Auer wrote:
> On Sat, 2008-11-15 at 14:40 +0100, Jef Driesen wrote:
>> 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'
> 
> What happens? What output do you see, if any?
> 
> Does this script work?
> 
>    X="echo fred"
>    $X | grep fred
> 
> It should output
> 
>    fred
> 
> If that works, try this:
> 
>    #!/bin/sh
>    X="echo fred"
>    $X | sed s/fred/martha/
> 
> It should output
> 
>    martha
> 
> If both those work, I suspect dos2unix does not output what you think it
> outputs. As far as I can tell, dos2unix outputs nothing unless it has a
> problem with a conversion (it converts in place by default), so I'm a
> bit puzzled about what sed is supposed to be doing.

He needs to do the conversion first (fromdos) and then (&&) cat the 
converted file to sed.

-- 
       +---------------------------------+-------------------+
       | 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