views:

36

answers:

1

Hi, 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 )

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

Looking around I found this:

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

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

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

Any other ideas?

+2  A: 

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

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

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. If your machine has no seq it might have jot (BSD/OSX):

    foreach number ( `jot 9` )
    

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

  2. Use bash with built-in brace expansion:

    for number in {1..9}
    
schot
Yes, I had noticed the lack of $, still didn't work. Was looking for something simple than the awk command you show, but will have it in mind for the future. Thanks anyway!
Thomas
@Thomas: What OS are you using? I noticed my Mac has the GNU version of `seq` installed as `gseq`, perhaps you have something similar on your system. Good luck!
schot
Im using Mac as well, but gseq appears as not found as well...
Thomas
@Thomas: I got it through [MacPorts](http://www.macports.org/)'s coreutils package. But you should have `jot` available as an alternative.
schot
@schot: jot works beautifully! Thank you for your help.
Thomas
+1 for jot - I learned something new today !
Paul R