Simple shell script for generating hex numbers of a certain range?

Here's an implementation tested in KSH on OpenBSD (should work with any Bourne shell, doesn't rely on bash features).

Here's an implementation tested in KSH on OpenBSD (should work with any Bourne shell, doesn't rely on bash features). #! /bin/sh START=$1 END=$2 function h2d { echo "ibase=16; $@"|bc } function d2h { echo "obase=16; $@"|bc } # convert to decimal START_DEC=`h2d ${START}` END_DEC=`h2d ${END}` # find length of last hex number LENGTH=`expr ${#END} - 1` for I in `nawk "BEGIN{ for(i=${START_DEC};i output.txt.

I'm almost there having picked through some simple commands and cobbled a very simple script together that pads properly and creates exactly the output I need: #! /bin/sh #Script to test for loop i=10 #put start num in here j=20 #put end num in here for (( a=i ; a > output. Txt done.

While my version isn't optimized for brevity or speed, it does meet all of the stated requirements. In particular, the dynamic padding based on the input, which isn't accounted for here (and is responsible for the length of the script). – chuckx Apr 1 at 20:08 This is not a Shell script.

For (( ... )) is a non-portable shell extension (certainly not POSIX) and deviates from your original spec in that now the output is 0-padded to 5 digits no matter what the start and end numbers are, and prefixed with &#. It would have been better to state your actual requirements in the first place... – Jens Aug 18 at 19:33.

Here's a script that's portable (any POSIX shell will do), should work blazingly fast (no forks to nawk, bc, etc...) and adheres to the poster's spec. #! /bin/sh # # hexcount - POSIX Shell script to count from $1 to $2 in hex, # separated by ";" and with the precision set to the # maximum digits of $1 and $2.

# Usage: hexcount lo hi # Example: hexcount FFF 1200 FROM=$1 TO=$2 if test ${#FROM} -gt ${#TO}; then FORMAT="%0${#FROM}X;" else FORMAT="%0${#TO}X;" fi FROM=$(printf '%d' 0x$FROM) TO=$(printf '%d' 0x$TO) while test $FROM -le $TO; do printf $FORMAT $FROM FROM=$((FROM+1)) done printf '\n' Ain't printf cool?

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions