如何将项目附加到 csh 列表?

use*_*008 3 csh list

我想创建一个列表,其中包含适用于 csh 中某些条件的字符串。

如何在不预先确定列表或数组的大小的情况下以动态方式添加到列表或数组?

c shell 中是否有 list.add 或类似的东西?

谢谢

Mar*_*oij 5

您可以只使用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)

  • 使用“set my_list = ($my_list:q more)”来避免空格问题:http://stackoverflow.com/questions/13149637/csh-adding-strings-to-an-array-whitespace-troubles (2认同)