我想使用 csh 脚本将两个数组的相应元素合并到另一个数组中。我的脚本给出的错误为:-
arrayfinal[1]:不匹配。结果是 0 0 0 0 0
我的脚本是
#!/bin/csh
set array1 = {1,2,3,4,5}
set array2 = {1,4,9,16,25}
#set arrayfinal={`$array1[1]+$array2[1]`}
@ count=$#array1
@ index =1
set arrayfinal = {0,0,0,0,0}
while ($index <= $count)
arrayfinal[$index] =array1[$index]+array2[$index]
@ index++
echo "the results is $arrayfinal"
exit 0
谢谢。
答案1
您缺少end
定界循环while
,缺少for 算术表达式之一,并且您的语法@
存在一些问题:@
#!/bin/csh
set array1 = {1,2,3,4,5}
set array2 = {1,4,9,16,25}
@ count = $#array1
@ index =1
set arrayfinal = {0,0,0,0,0}
while ($index <= $count)
@ arrayfinal[$index] = $array1[$index] + $array2[$index]
@ index++
end
echo "the results is $arrayfinal"
exit 0