如何在UNIX中为变量赋值参数?

时间:2010-04-24 16:00:00

标签: unix variables parameters options

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

这不符合我的预期:

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

有什么想法吗?

1 个答案:

答案 0 :(得分:8)

删除set

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

或者如果你想设置它以便在shell中运行的后续程序可用:

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

export关键字的描述相当不错here