我该如何向csh列表中添加项目?

3
我希望创建一个包含符合csh中某些条件的字符串的列表。
如何以动态方式向列表或数组添加内容,而不需要预先确定列表或数组的大小?
在c shell中是否有list.add或类似的函数?
谢谢。
1个回答

6
您可以使用如下形式的表达式: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

4
使用 "set my_list = ($my_list:q more)" 来避免空格问题:https://dev59.com/pWrWa4cB1Zd3GeqP80K8 - MaMazav

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接