views:

45

answers:

3

Have a shell script that reads the files in a particular directory.

#!/bin/bash
for fspec in /exp/dira/test/ready/* ; do
done

I want to modify the unix shell script so that path is retreived from enviornmental variable.

export CUST_DATA=${_FX_DATA_}/test have set this variable in environment thru .profile

#!/bin/bash
READY_FILES= "$CUST_DATA/ready"
for fspec in $READY_FILES/* ; do
done

i tried the above but it's not working.

A: 

add echo "<$CUST_DATA>" to your second script to make sure that variable is not set.

sha
Thanks a lot for the info
Arav
+1  A: 
    #!/bin/bash
    . ~/.profile
    READY_FILES="$CUST_DATA/ready"
    for fspec in $READY_FILES/* ; do
     ...
    done
ghostdog74
Thanks a lot for the info
Arav
Should quote `"$READY_FILES"` in the `for` statement. Always quote variables unless you have a specific reason not to.
glenn jackman
+5  A: 

The space after the equal sign makes it mean something completely different.

#!/bin/bash
READY_FILES="$CUST_DATA/ready"
for fspec in "$READY_FILES"/* ; do
  ....
done
Ignacio Vazquez-Abrams
Good use of quotes to work even if `$READY_FILES` contains whitespace.
John Kugelman
Thanks a lot for the info
Arav