count in hex

Posted on 2009-05-19
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$ ./ 0xC1
./[7]: 0xC1: bad number

If I leave LUNID as null, it will successfully count from 0. Help appreciated.
# script to create EMC mappings
# set lun to hex
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
        echo "LUNID is: ${LUNID#16#}"

Open in new window

Question by:Rowley
  • 3
  • 3
LVL 68

Expert Comment

ID: 24421931
How about 16#C1  ?
LVL 68

Accepted Solution

woolmilkporc earned 500 total points
ID: 24422024
... or use in your script
and give only C1 as the argument.
LVL 13

Author Comment

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


Which seemed to do the trick. I'll try the other suggestions later. Cheers!
ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

LVL 13

Author Comment

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

Expert Comment

ID: 24422954
what do you mean with 'base value'?
If the goal was to remove the '16#' part, that's what you already did -
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
LVL 13

Author Comment

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



Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Replace a tag with sed 2 49
incorrect file reading in bash 7 106
vi editor showing strange character when i hit spacebar everytime 2 65
Bash Script to Analyze Oracle Schemas 11 104
Installing FreeBSD… FreeBSD is a darling of an operating system. The stability and usability make it a clear choice for servers and desktops (for the cunning). Savvy?  The Ports collection makes available every popular FOSS application and packag…
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
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 previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

770 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