我正在UNIX中编写一个程序加倍编号
if [ $# == l ]; then
let "twice=$l*2
if [ $? == 0 ]; then
clear
echo "twice Program"
echo "-------------"
echo "l * 2 = $twice"
exit 0
else
clear
echo "The argument must be an integer."
exit 1
fi
exit 0
else
clear
echo "Only one argument is acceptable with twice."
echo :Usage: twice argument"
exit 1
fi
答案 0 :(得分:0)
您在第二行打开双引号,但未正确关闭。
let "twice=$l*2
应该是
let "twice=$1*2"
shell解释器在处理不相关的双引号时会出现阻塞。
请注意,您也会在多个地方将l
(ell)字母与数字1
(一个)混淆,因为它不会让shell了解您的脚本。
答案 1 :(得分:0)
您正在使用l(小L)而不是1
if [ $# == 1 ]
then
let "twice=$1*2"
if [ $? == 0 ]; then
echo "twice Program"
clear
echo "-------------"
echo "$1 * 2 = $twice"
exit 0
else
clear
echo "The argument must be an integer."
exit 1
fi
exit 0
else
clear
echo "Only one argument is acceptable with twice."
echo ":Usage: twice argument"
exit 1
fi