我怎麼能寫這樣的:如何中編寫一個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