CShell 脚本中的语法错误
编写脚本读取正整数,然后计算以下序列: 如果数字是偶数,则减半 如果是奇数,则将其乘以 3 并添加 1
您应该重复此过程,直到该值为 1,打印出每个值以及您执行了多少次操作。
#! bin\csh
echo "please enter any integer number :) "
set count=0
set number=$<
while($number != 1)
if($number % 2) then
@ number = number * 3 + 1
else
@ number = number / 2
endif
echo " $number "
@ count = count ++
end
echo I performed these operations $count times
当我运行脚本时,出现以下错误: @:表达式语法。
Write Script to read a positive integer number then it computes the following sequence:
If the number is even, halve it
If it is odd multiply it by 3 and add1
You should repeat this process until the value is 1, printing out each value and how many of these operations you performed.
#! bin\csh
echo "please enter any integer number :) "
set count=0
set number=lt;
while($number != 1)
if($number % 2) then
@ number = number * 3 + 1
else
@ number = number / 2
endif
echo " $number "
@ count = count ++
end
echo I performed these operations $count times
When I run the script I get the following error:@: Expression Syntax.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我相信它的 $ 变量可以获取其值
源http://www.eng.hawaii。 edu/Tutor/csh.html
所以那就是
这句话
让我颤抖
I believe its $variable to obtain its value
source http://www.eng.hawaii.edu/Tutor/csh.html
So that would be
And the line
makes me shiver
我得到正确的解决方案:)
i get correct solution :)