我是csh脚本的新手这是我第一次写任何脚本:下面是代码:
#!/bin/csh
#arg1 path
#arg2 condition
#arg3 number of files
#arg4-argN name of files
set i=0
while ( $i < $3 )
if ($2 == 0) then
cp /remote/$1/$($i+4) $1/new.$( $i+4 )
p4 add $1/new.$($i+4)
else
p4 edit $1/new.$($i+4)
cp /remote/$1/$($i+4) $1/new.$($i+4)
endif
$i = $i+1
end 但在这里,我对得到的错误保持警惕。变量名非法。我已经读了一些教程,但没有得到任何相关的东西。请帮帮忙。adv.中的Thx
发布于 2017-04-05 14:24:37
您可以在第一行中使用标志-v和-x来查看脚本执行的操作
#!/bin/csh -vx问题出现在尝试将四加到计数器变量中的部分
$($i+4)csh不能以这种方式添加。我会使用一个临时变量将计数器加4,然后在所有调用中使用该变量
@ i = 0
while ( $i < $3 )
@ iplusfour = $i + 4
if ($2 == 0) then
cp /remote/$1/$($i+4) $1/new.$iplusfour
p4 add $1/new.$iplusfour
else
p4 edit $1/new.$iplusfour
cp /remote/$1/$iplusfour $1/new.$iplusfour
endif
@i = $i + 1
end 我还吸收了Willams的评论。
发布于 2019-07-22 04:00:03
最后一个增量可以简化为@ i++,即修饰Muluman88的解决方案:
@ i = 0
while ( $i < $3 )
@ iplusfour = $i + 4
if ($2 == 0) then
cp /remote/$1/$($i+4) $1/new.$iplusfour
p4 add $1/new.$iplusfour
else
p4 edit $1/new.$iplusfour
cp /remote/$1/$iplusfour $1/new.$iplusfour
endif
@ i++
end 确保在@符号后面有(空格)。
https://stackoverflow.com/questions/15082044
复制相似问题