Click to See Complete Forum and Search --> : bash script scalar doesnt get affected


dnux67
09-15-2005, 03:21 PM
Hi could someone tell me why my scalar that inside all the if condition doesnt get affected? when they are call in the sed substitution they only get affected with the STDIN but with my default value if the STDIN was empty.
Thank you all for your help

Dee

here one exemple of my if condition

echo "please enter the port number"
read C_portNum
if [ -z C_portNum ]; then
C_portNum="21"
fi
cat proftpd.newConf | sed -e "s/PORT_NUMBER/$C_portNum/" > test.newConf

bwkaz
09-15-2005, 06:37 PM
I'm not entirely sure what you want to happen, but from your code, this:

if [ -z C_portNum ]; then appears to be incorrect. This test will always evaluate to false, because the string "C_portNum" is never the empty string.

What you need is something like this:

if [ -z "$C_portNum" ] ; then

so that it looks at the value of the variable C_portNum, not the string C_portNum itself. (The quotes are there to make it work even if the variable isn't set to anything.)