Operating System - HP-UX
1823920 Members
3088 Online
109667 Solutions
New Discussion юеВ

any suggestion to increment in hex in a for loop ?

 
SOLVED
Go to solution
Q4you
Regular Advisor

any suggestion to increment in hex in a for loop ?

looking for a quick suggestion to increament in HEX ( instead of decimal) in a for loop to create large number of VGs ( appx 188)

Basically, I want to use minor number(YY) for the VG02 to VG95 (XX) in the following command :

mknod /dev/vgXX/group c 64 0xYY0000

XX should increment in decimal, start at 02
YY should increment in HEX, start at 02

TIA
-Q
3 REPLIES 3
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: any suggestion to increment in hex in a for loop ?

You can leverage the printf command to do this for you.

---------------------------------------
#!/usr/bin/sh

typeset -i I=2
typeset -i STOP=95

while [[ ${I} -le ${STOP} ]]
do
typeset DEC=$(printf "%02d" ${I})
typeset HEX=$(printf "%02x" ${I})
echo "DEC: ${DEC} HEX: ${HEX}"
# mkdir /dev/vg${DEC} -p -m 750
# mknod /dev/vg${DEC}/group c 64 0x${HEX}0000
((I += 1))
done
----------------------------------------

Uncomment the mkdir and mknod lines when you are confident.
If it ain't broke, I can fix that.
Q4you
Regular Advisor

Re: any suggestion to increment in hex in a for loop ?

Worked like a champ ! Thanks !
Q4you
Regular Advisor

Re: any suggestion to increment in hex in a for loop ?

Solved the problem, so closing it :)