在tcsh中生成序列号列表 [英] Generating sequential number lists in tcsh

查看:99
本文介绍了在tcsh中生成序列号列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试找到一种解决方法,以便在tcsh中广泛定义连续编号列表,即而不是这样做:

I've been trying to find a workaround to defining lists of sequential numbers extensively in tcsh, ie. instead of doing:

i = ( 1 2 3 4 5 6 8 9 10 )

我想做这样的事情(知道它不起作用)

I would like to do something like this (knowing it doesn't work)

i = ( 1..10 )

这是在foreach循环中特别有用(我知道我可以用一段时间,只是想寻找一个替代方法。)。

This would be specially usefull in foreach loops (I know I can use while, just trying to look for an alternative).

环顾四周,我发现:

foreach $number (`seq 1 1 9`)
...
end

发现此处。他们说它将生成一个以1开头的数字列表,以1递增的数字以9结尾。

Found that here. They say it would generate a list of number starting with 1, with increments of 1 ending in 9.

我尝试过,但是没有用。显然seq不是命令。是否存在或这是完全错误的?

I tried it, but it didn't work. Apparently seq isn't a command. Does it exist or is this plain wrong?

还有其他想法吗?

推荐答案

seq 当然存在,但可能不在您的系统上,因为它不在POSIX标准中。我只是注意到您的命令中有两个错误。以下工作有效吗?

seq certainly exists, but perhaps not on your system since it is not in the POSIX standard. I just noticed you have two errosr in your command. Does the following work?

foreach number ( `seq 1 9` )
    echo $number
end

请注意,省略了美元符号和 seq 命令。

Notice the omission of the dollar sign and the extra backticks around the seq command.

如果仍然不起作用,您可以使用<$来模拟 seq c $ c> awk :

If that still doesn't work you could emulate seq with awk:

foreach number ( `awk 'BEGIN { for (i=1; i<=9; i++) print i; exit }'` )



更新



另外两种选择:

Update

Two more alternatives:


  1. 如果您的计算机没有 seq 它可能具有 jot (BSD / OSX):

  1. If your machine has no seq it might have jot (BSD/OSX):

foreach number ( `jot 9` )

我从未听说过 jot 之前,但在类固醇上看起来像 seq

I had never heard of jot before, but it looks like seq on steroids.

使用 bash 进行内置括号扩展:

Use bash with built-in brace expansion:

for number in {1..9}


这篇关于在tcsh中生成序列号列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆