[ILUG] Re: little sh question

From: Kevin Lyda (kevin.lyda at domain itg.ie)
Date: Wed 03 May 2000 - 16:30:17 IST


paul jakma asked me this today and i've often wanted to do similar things.
suddenly today i came up with an easier way then using expr.

On Tue, May 02, 2000 at 07:52:04PM +0100, Paul Jakma wrote:
> how do you do numerical expansion in sh/bash, ie
>
> i want a for loop to iterate a variable through 001 to 254. In BASIC you
> can do something like:

adjust the argument to head accordingly:

for f in `yes "" | head -2 | cat -n|sed 's/ /0/g;s/.*\(....\)$/\1/'`; do
    echo $f
done

mmmmm. damn that's sexy!

if you can live without the 001, 002, 003; and just settle on 1, 2, 3 then
it's a bit easier:

for f in `yes "" | head -2 | cat -n`; do
    echo $f
done

ah, any day that you can find yes useful is just great!

kevin



This archive was generated by hypermail 2.1.6 : Thu 06 Feb 2003 - 13:06:00 GMT