views:

27

answers:

1
#!/bin/bash
if [ ! $1 ]
then
 echo "no param"
else
    set FAV_COLOR=$1
    echo "My fav color is ${FAV_COLOR}"
fi

This is not working how i expected:

>favcol.sh blue
My fav color is FAV_COLOR=blue

any thoughts?

+7  A: 

Remove set.

FAV_COLOR=$1
echo "My fav color is ${FAV_COLOR}"

Or if you want to set it so that it is available to subsequent programs run in the shell:

export FAV_COLOR=$1
echo "My fav color is ${FAV_COLOR}"

The export keyword is described fairly well here.

Stephen
For values of "global" than mean affecting all the descendant processes of the current shell, anyway.
dmckee
@dmckee, thanks clarified.
Stephen