在tcsh中生成序列号列表

编程入门 行业动态 更新时间:2024-10-18 22:34:16
本文介绍了在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:

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

  • 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中生成序列号列表

    本文发布于:2023-10-26 23:48:04,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1531698.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:序列号   列表   tcsh

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!