OT: bash help

Mike Wright mike.wright at mailinator.com
Sat Aug 16 21:44:14 UTC 2014


Hi all,

I'm trying to write a simple script that if provided an argument, uses 
that, or if nothing is provided, uses a predefined string.

if [ -n $# ]
then
     WORDS=$1
else
     WORDS="these are some words"
fi
echo $WORDS;

The second case is always comes back "".

But if I write

WORDS='these are some words'
echo $WORDS

I get the assigned string.

Why doesn't the assignment work when inside an if/then?  How do I make 
it work?  What's the difference between the case where the assignment is 
inside the if/then and outside the if/then?

TIA,
Mike Wright


More information about the users mailing list