该脚本应该打印“输入要添加的嵌套编号:”并继续执行此操作,直到用户输入负数。此时它应该打印正数的总和。然而,正如循环要求下一个数字一次,它被输入,然后不再询问,脚本只是停止做任何事情,甚至没有到达循环中的下一行。
#!/bin/csh -x
#
# This script adds positive numbers entered by the user, stopping
# when a negative number is added
# Usage: +#, +#, +#... -#.
#
@ x=0
@ sum = 0
while($x>= 0)
echo -n "Enter the next number to be added: "
@ sum = $sum + $<
@ x = $<
end
#
exit 0