| 1 | #!/bin/bashscip-shell filesystem . . `/bin/bash`. |
| 2 | # hexconvert.sh: Convert a decimal number to hexadecimal. |
| 3 | |
| 4 | E_NOARGS=85 # Command-line arg missing. |
| 5 | BASE=16 # Hexadecimal. |
| 6 | |
| 7 | if [scip-shell system . . `[`. -z "$1" ] |
| 8 | then # Need a command-line argument. |
| 9 | echoscip-shell system . . echo. "Usage: $0 number" |
| 10 | exit $E_NOARGS |
| 11 | fi # Exercise: add argument validity checking. |
| 12 | |
| 13 | |
| 14 | hexcvtscip-shell shell abs-guide 10-4 hexcvt(). () |
| 15 | { |
| 16 | if [scip-shell system . . `[`. -z "$1" ] |
| 17 | then |
| 18 | echoscip-shell system . . echo. 0 |
| 19 | return # "Return" 0 if no arg passed to function. |
| 20 | fi |
| 21 | |
| 22 | echoscip-shell system . . echo. ""$1" "$BASE" o p" | dc |
| 23 | # o sets radix (numerical base) of output. |
| 24 | # p prints the top of stack. |
| 25 | # For other options: 'man dc' ... |
| 26 | return |
| 27 | } |
| 28 | |
| 29 | hexcvtscip-shell shell abs-guide 10-4 hexcvt(). "$1" |
| 30 | |
| 31 | exit |