我想创建一个列表,其中包含适用于 csh 中某些条件的字符串。
如何在不预先确定列表或数组的大小的情况下以动态方式添加到列表或数组?
c shell 中是否有 list.add 或类似的东西?
谢谢
您可以只使用set my_list = ( $my_list more ). 例如:
# Create original list
% set my_list = ( hello world )
% echo $my_list
hello world
# Append to the list
% set my_list = ( $my_list hey there )
% echo $my_list
hello world hey there
# Loop over the list to verify it does what we expect it to do
% foreach item ($my_list)
foreach? echo "-> $item"
foreach? end
-> hello
-> world
-> hey
-> there
Run Code Online (Sandbox Code Playgroud)