用于的c shell转义字符的问题*
首先,这是家庭作业。我只是在努力解决一些我无法通过谷歌找到太多信息的问题 问题是打印从1到输入数字的整数的乘积 如果我们输入4,我们就得到24(1*2*3*4)作为输出 我的问题是,我不知道如何转义*字符以将其连接到字符串。我在bourne shell上做过这项工作,但在c shell中一直遇到这个问题用于的c shell转义字符的问题*,shell,csh,Shell,Csh,首先,这是家庭作业。我只是在努力解决一些我无法通过谷歌找到太多信息的问题 问题是打印从1到输入数字的整数的乘积 如果我们输入4,我们就得到24(1*2*3*4)作为输出 我的问题是,我不知道如何转义*字符以将其连接到字符串。我在bourne shell上做过这项工作,但在c shell中一直遇到这个问题 @ temp = 1 @ ans = 1 while ( $temp <= $number ) @ ans = ( $ans * $temp ) @ temp = ( $t
@ temp = 1
@ ans = 1
while ( $temp <= $number )
@ ans = ( $ans * $temp )
@ temp = ( $temp + 1 )
end
set ans = "$ans ("
@ count = 1
while ( $count <= $number )
set ans = "$ans$count"
@ count = ( $count + 1 )
if ( $count <= $number ) then
set ans = "$ans*"
endif
end
set ans = "$ans)"
echo $ans
@temp=1
@ans=1
而($temp
编辑
echo所需的报价:
echo "$ans"
回显变量时,在变量周围使用双引号(echo“$ans”
),以避免在变量值中使用shell展开元字符:
(脚本文件:prod.csh
):
考虑过这个。实际上在发布之前已经尝试过了。我仍然得到了一个回音:不匹配。当尝试回音出ans时。你正在链接到一个bash问题。这是关于csh的。顺便说一下,你也可以使用set noglob
,这有时很有用,因为在某些情况下添加引号可能会变得很棘手。
echo "$ans"
#!/bin/tcsh
@ number = 6
@ temp = 1
@ ans = 1
while ( $temp <= $number )
@ ans = ( $ans * $temp )
@ temp = ( $temp + 1 )
end
set ans = "$ans ("
@ count = 1
while ( $count <= $number )
set ans = "$ans$count"
@ count = ( $count + 1 )
if ( $count <= $number ) then
set ans = "$ans*"
endif
end
set ans = "$ans)"
echo "$ans"
$ tcsh prod.csh
720 (1*2*3*4*5*6)
$