[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: bash scripting question



Tyler Smith wrote:
On 2007-05-17, Bob McGowan <bob_mcgowan@symantec.com> wrote:
Some general comments, mostly aimed at making your code cleaner without changing what it does.

First, both 'echo' and 'printf' put their results on standard out. Your call of 'printf' is inside command substitution, so its STDOUT becomes
--snipped stuff--

Oh, great, thanks. I added the echo to stop getting the complaint
about unknown command, but this is better.

So, cut and pasted from a bash shell:

$ lab_num=41
$ lab_let=$(printf "\x$lab_num")
$ echo $lab_let
A
$ ((lab_num++))
$ lab_let=$(printf "\x$lab_num")
$ echo $lab_let
B

Much improved!

This would need two loops, the outer to increment the 'tens' digit, the inner to increment the 'ones' digit, but it would do the trick. For example:

x=(0 1 2 3 4 5 6 7 8 9 A B C D E F)


I knew there was an array form in bash, but I couldn't find it. I'm
working from the O'Reilly book classic shell scripting, and the only
reference to arrays is in relation to awk scripts. This is a big help.

Thanks alot!

Tyler



You're welcome ;)

Bob

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature


Reply to: