Linux Foreach loop赢了';跑不动

Linux Foreach loop赢了';跑不动,linux,shell,Linux,Shell,家庭作业是修改这个脚本,将exec作为参数,但首先我希望能够运行这个脚本,尝试找出如何修改它 tcsh $ cat foreach_1 #!/bin/tcsh # routine to zero-fill argv to 20 arguments # set buffer = (0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0) set count = 1 # if ($#argv > 20) goto toomany # foreach argument

家庭作业是修改这个脚本,将exec作为参数,但首先我希望能够运行这个脚本,尝试找出如何修改它

tcsh $ cat foreach_1
#!/bin/tcsh
# routine to zero-fill argv to 20 arguments
#

set buffer = (0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0)
set count = 1
#
if ($#argv > 20) goto toomany
#
foreach argument ($argv[*])
set buffer[$count] = $argument
@ count++
end
# REPLACE command ON THE NEXT LINE WITH
# THE PROGRAM YOU WANT TO CALL.
exec command $buffer[*]
#
toomany:
echo "Too many arguments given."
echo "Usage: foreach_1 [up to 20 arguments]"
exit 1
但我在尝试运行它时遇到以下错误:

./foreach_1: line 5: syntax error near unexpected token `('
./foreach_1: line 5: `set buffer = (0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0)'
我没有任何额外的引号,那么为什么会发生这种情况呢?

在许多shell中(我相信tcsh是伯恩兼容的),您必须将表达式的左侧、
=
和右侧都直接相邻

# shorten the ` = ` to `=` below:
set buffer=(0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0)
set count=1

if ($#argv > 20) goto toomany
#
foreach argument ($argv[*])
set buffer[$count] = $argument
@ count++
end
# REPLACE command ON THE NEXT LINE WITH
# THE PROGRAM YOU WANT TO CALL.
exec command $buffer[*]
#
toomany:
echo "Too many arguments given."
echo "Usage: foreach_1 [up to 20 arguments]"
exit 1