Variables in shell script not working

Karl Auer kauer at biplane.com.au
Sat Nov 15 13:30:47 UTC 2008


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

Regards, K.

-- 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Karl Auer (kauer at biplane.com.au)                   +61-2-64957160 (h)
http://www.biplane.com.au/~kauer/                  +61-428-957160 (mob)

GPG fingerprint: DD23 0DF3 2260 3060 7FEC 5CA8 1AF6 D9E3 CFEE 6B28

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
URL: <https://lists.ubuntu.com/archives/ubuntu-users/attachments/20081116/40456167/attachment.sig>


More information about the ubuntu-users mailing list