Solved

count in hex

Posted on 2009-05-19
6
680 Views
Last Modified: 2013-12-26
Hi folks,

I need a script to count in hex when passed from $1. I've managed to figure out so much, don't have time to carry on at the moment and could use come help.

If I try and pass a hex value in any format and try to set it from $1 I get:

root@host/export/home/user$ ./create-map.sh 0xC1
./create-map.sh[7]: 0xC1: bad number

If I leave LUNID as null, it will successfully count from 0. Help appreciated.
#!/usr/bin/ksh
# script to create EMC mappings
 
# set lun to hex
LUNID=$1
typeset -i16 LUNID
 
touch /var/tmp/host-lunmap
 
for dev in `cat /var/tmp/devs-host`; do
        echo "map dev $dev to dir 07C lun=$LUNID" >> /var/tmp/host-lunmap
        echo "map dev $dev to dir 10C lun=$LUNID" >> /var/tmp/host-lunmap
        ((LUNID=LUNID+1))
        echo "LUNID is: ${LUNID#16#}"
done

Open in new window

0
Comment
Question by:Rowley
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 24421931
How about 16#C1  ?
wmp
 
0
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 500 total points
ID: 24422024
... or use in your script
LUNID=16#$1
and give only C1 as the argument.
0
 
LVL 13

Author Comment

by:Rowley
ID: 24422042
Cool, thanks. I ended up figuring it out anyway as I had some more time to dig. Ended up using:

let LUNID=LUNID+16#$INI

Which seemed to do the trick. I'll try the other suggestions later. Cheers!
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 13

Author Comment

by:Rowley
ID: 24422664
OK...I saw somewhere how to remove the base value from the string, extra brownie points if you could help with that!
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 24422954
Well,
what do you mean with 'base value'?
If the goal was to remove the '16#' part, that's what you already did -
${LUNID#16#}
From ksh docs -
${variable#pattern}     If the pattern matches the beginning of the variable's value, delete the shortest part that matches and return the rest
0
 
LVL 13

Author Comment

by:Rowley
ID: 24426848
Ahhh, so I did. Forgot to do the same to the lun=$LUNMAP bit.

heh...

thanks.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question