1

它是我程序的一部分,

output="$(./t1)"        // output=5

echo $output            // It displays 5

if test $output -eq 5
then
echo "five"             // this if statement works and displays 'five'
fi

case $output in          **// this case is not working and giving just default value**

1) echo "one" ;;

2) echo "two" ;;

3) echo "three" ;;

4) echo "four";;

5) echo "five";;

*) echo "wrong choice" ;;

esac                    // output is wrong choice though it works proper in if statement   

我的 bash 脚本有什么错误吗?请帮忙。

4

1 回答 1

1

This works for me:

output=$(./t1)
echo $output
if test $output -eq 5; then echo "five"; fi
case $output in
  1) echo "one" ;;
  2) echo "two" ;;
  3) echo "three" ;;
  4) echo "four";;
  5) echo "five";;
  *) echo "wrong choice" ;;
esac

When you had the " around $(./t1) the result was a string, not a numeric value. This worked with test, but not case. Also you has a couple of missing ; in the post and // is not valid for comments in bash.

于 2013-04-20T07:17:35.310 回答