DISCLAIMER:
This script is as is. I give no warranty it will work as you expected on your system. You are running it at your own risk. If something goes wrong because of this script, I bear no responsibility.
Language:
bash
Platform:
Solaris 10
server# bash –version
GNU bash, version 3.00.16(1)-release (sparc-sun-solaris2.10)
Copyright (C) 2004 Free Software Foundation, Inc.
Purpose:
You have a starting, and ending device number in hexadecimal format. You want to print out the devices which fall between first and last device numbers.
Condition:
The device numbers given at command line must be hexadecimal (script will treat them as hexadecimal).
Usage:
Example 1: Print out the devices between 1AB0 and 1ABF
server# print_devs.bash 1AB0 1ABF
1AB0
1AB1
1AB2
1AB3
1AB4
1AB5
1AB6
1AB7
1AB8
1AB9
1ABA
1ABB
1ABC
1ABD
1ABE
1ABF
server#
Actual Script:
#!/bin/bash
# A script to generate the range of hex numbers between first and last hex number given at command line
# To run: ./print_devs.bash 21aa 21eb
# Read the given arguments and assign to first and last given value
firsthex=`echo $1 | tr “[:lower:]” “[:upper:]” `
lasthex=`echo $2 | tr “[:lower:]” “[:upper:]” `
# Set up h2d function which will convert hex to dec and vice versa
function h2d {
echo “ibase=16; $@”|bc
}
function d2h {
echo “obase=16; $@”|bc
}
# Convert first and last numbers into dec
firstdec=`h2d $firsthex`
lastdec=`h2d $lasthex`
if [ $lastdec -lt $firstdec ]; then
echo “Range given is incorrect – last number is smaller than first number”
fi
## For numbers between the firstdec and lastdec, print the hex on screen
for ((i=$firstdec;i do
echo `d2h $i`
done
No comments yet.