Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


New on LowEndTalk? Please Register and read our Community Rules.

All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.

Help Needed: Scripting

LivingSouLLivingSouL Member
edited January 2013 in General

I'm a n00b on programming/scripting so if anyone can help me please, I'd appreciate it.

How do you output hex chars on shell script? My goal is 5 characters long and increments it up until the end.

00000
00001
. . .
. . .
0000A
...
0001F

thank you!

Comments

  • Kabayan:

    Try this

    max=39
    for((i=0;i<=max;i++))
    do
    str=$(printf "%05x" $i)
    echo $str
    done

    Just replace 39 with a very high value

  • LivingSouLLivingSouL Member
    edited January 2013

    salamat! :D

    here's the output

    ./test: line 6: syntax error: unexpected end of file

    oh my bad.. "done" is actually part of it.. Thanks! :)

  • jcalebjcaleb Member
    edited January 2013

    Try
    bash test

  • prae5prae5 Member
    edited January 2013

    -

  • Or put a
    #!/bin/bash on top of file

  • #!/bin/bash
    #
    # 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'
    
    
    ./count.sh 00000 000A
    00000;00001;00002;00003;00004;00005;00006;00007;00008;00009;0000A;
    
  • Nice code

  • woah.. cool.. thanks @jcaleb and @prae5

Sign In or Register to comment.