开发者

How to do this on the tcsh shell in linux

I want to efficiently do the following on the tcsh in Linux.

somecommand a;
somecommand b;
somecommand c;

If I do somecommand {a,b,c},开发者_如何学编程 this does somecommand a b c, which is not what I want. Is there a way to do what I want?


In tcsh, you should use a foreach loop, like this :

foreach val (a b c)
  somecommand $val
end

Better yet would be to have the values in a variable, like this :

set values="a b c"

foreach val ($values)
  somecommand $val
end


In Bash, it's for i in a b c; do somecommand $i; done. I bet it's similar in tcsh.


@Borealid's loop is best. Just for kicks, another way is to use xargs:

echo a b c | xargs -n 1 somecommand


Thanks Boralid and John for your answers. I have created an alias in tcsh for this. It works!!

alias myglob 'echo \!:2-$ | xargs -n 1 \!:1'
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜