我怎么能写这样的:如何中编写一个if语句if语句
if $1 = a then
检查第二条语句if $2 is b then echo a and b
else $1 = 1 then
检查第二条语句if $2 = 2 then echo 1 and 2
...所有的变量都是字符串?
这是我有:
fun() {
if [ "$1" == "a" ]; # when $1 is a then
then
if [ "$2" == "" ]; # $1 is a and $2 is empty string
echo a
elif [ "$2" == "b" ]; # $1 is a and $2 is b
then
echo "a and b"
fi
fi
else
if [ "$1" == "1" ]; # when $1 is 1 then
then
if [ "$2" == "" ]; # $1 is 1 and $2 is empty string
echo a
elif [ "$2" == "2" ]; #$1 is 1 and $2 is 2
then
echo "1 and 2"
fi
fi
}
'之开关应该效果更好 – ajreal 2011-06-07 09:42:56
使用嵌套的'case'声明可以帮助你:http://stackoverflow.com/questions/1477518/nested-case-in-bash-script – eckes 2011-06-07 09:45:53
和问题在哪里? – Rajish 2011-06-07 09:47:14