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
--
users mailing list
users@lists.fedoraproject.org
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Fedora Code of Conduct: http://fedoraproject.org/code-of-conduct
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines
Have a question? Ask away: http://ask.fedoraproject.org

Reply via email to