将条目添加到循环内的数组中

将条目添加到循环内的数组中

我正在尝试更新 linux tcsh 脚本中的数组。该脚本使用 while 循环,我想在每次循环迭代时向数组添加元素。有一个更好的方法吗?

#!/bin/tcsh
clear
set x = 1
while ($x <= 10)

echo "Enter a number..."
set number = $<
set numbers = ('0', '0', '0', '0', '0', '0', '0', '0', '0', '0')
set numbers[$x] = $number
echo "The number you entered was $number."

if ($number < 0) then
        exit 1
else if (0 <= $number && $number < 100) then
        echo "The number is out of range. Please enter another number."
endif
echo $numbers[1-]
#echo $number[10]
@ x++
end
@ y = $number[1]
echo $y

相关内容