Welcome, guest | Sign In | My Account | Store | Cart

Experimental

Bash, 27 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/bin/bash

err="\033[1;31m"
res="\033[1;36m"
end="\033[0m"

if [ $# -eq 1 ]; then
   n=$1
   case $n in
      *[[:xdigit:]])
         if [[ ${n:0:2} =~ 0[xX] ]]; then
            echo -e $res$n' = '$(($n))$end
         elif [[ ${n:0:1} =~ [xX] ]]; then
            echo -e $res'0'$n' = '$((0$n))$end
         elif [[ ${n:0:1} =~ [[:digit:]] && ! $n =~ [[:alpha:]] ]]; then
            printf $res$n' = 0x%X\n'$end $n
         elif [[ ${n:0:1} =~ [[:xdigit:]] ]]; then
            echo -e $res'0x'$n' = '$((0x$n))$end
         else
            echo -e $err'=>err'$end
         fi;;
      *)
         echo -e $err'=>err'$end;;
   esac
else
   echo -e $err'=>err'$end
fi
Created by greg zakharov on Mon, 1 Jul 2013 (MIT)
Bash recipes (41)
greg zakharov's recipes (59)

Required Modules

  • (none specified)

Other Information and Tasks