Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

bash question: go through hex-decimal numbers in a 'for' loop?

4 views
Skip to first unread message

liha...@gmail.com

unread,
Oct 15, 2008, 5:04:46 PM10/15/08
to
Is there an easy way to loop through hex-decimals i.e. [0-9a-z] in a
for loop, the following is not working:

for i in [0-9a-f]; do
/path/to/do/stuff "num_$i" &
done

I want to run the following commands:
/path/to/do/stuff num_0 &
/path/to/do/stuff num_1 &
/path/to/do/stuff num_2 &
.....
/path/to/do/stuff num_f &

many thanks,
lihao

Maxwell Lol

unread,
Oct 15, 2008, 5:31:37 PM10/15/08
to
"liha...@gmail.com" <liha...@gmail.com> writes:

> Is there an easy way to loop through hex-decimals i.e. [0-9a-z] in a
> for loop, the following is not working:
>
> for i in [0-9a-f]; do

for i in 0 1 2 3 4 5 6 7 8 9 a b c d e f; do

mop2

unread,
Oct 15, 2008, 6:26:58 PM10/15/08
to
On Wed, 15 Oct 2008 18:04:46 -0300, liha...@gmail.com <liha...@gmail.com> wrote:

> Is there an easy way to loop through hex-decimals i.e. [0-9a-z] in a
> for loop, the following is not working:
>
> for i in [0-9a-f]; do
> /path/to/do/stuff "num_$i" &
> done

$ $0 --version
GNU bash, version 3.2.39(1)-release (i686-pc-linux-gnu)
Copyright (C) 2007 Free Software Foundation, Inc.

$ for z in {0..9} {a..f};do echo $z\&;done
0&
1&
2&
3&
4&
5&
6&
7&
8&
9&
a&
b&
c&
d&
e&
f&

liha...@gmail.com

unread,
Oct 15, 2008, 9:47:55 PM10/15/08
to
On Oct 15, 6:26 pm, mop2 <inva...@mail.address> wrote:

exactly what I am looking for, many thanks. :-)

lihao


Stephane CHAZELAS

unread,
Oct 16, 2008, 2:20:36 AM10/16/08
to
2008-10-15, 14:04(-07), liha...@gmail.com:
[...]

awk 'BEGIN{ for(i = 0; i < 0x10; i++)
printf "num_%x\n", i}' | xargs -n1 /path/to/do/stuff

--
Stéphane

pk

unread,
Oct 16, 2008, 4:27:33 AM10/16/08
to

i=0
while [ $i -lt 16 ]; do
h=$(printf "%x" "$i")
do_stuff "num_$h" &
i=$((i+1))
done

Michael Schindler

unread,
Oct 16, 2008, 4:51:40 AM10/16/08
to
liha...@gmail.com wrote:


for i in {0..26}
do
/path/to/do/stuff "num_$(printf "%x" $i)" &
done

0 new messages