diff options
author | Jakob Kaivo <jkk@ung.org> | 2019-08-14 13:34:14 -0400 |
---|---|---|
committer | Jakob Kaivo <jkk@ung.org> | 2019-08-14 13:34:14 -0400 |
commit | bbad39de0ef340032cac0698c399509dca929c44 (patch) | |
tree | 99fc87b7562f00b9166142739c8a60d870085cca | |
parent | 07602b5ed3b84129d756373e861d9d19be578de4 (diff) |
add support for hex and octal output
-rw-r--r-- | ord.sh | 18 |
1 files changed, 16 insertions, 2 deletions
@@ -1,6 +1,20 @@ +format=d + +while getopts xdo opt; do + case $opt in + x|d|o) format=${opt};; + ?) exit 1;; + esac +done + +shift $((OPTIND - 1)) + if [ $# -ne 1 ] || [ ${#1} -ne 1 ]; then - printf 'usage: %s char\n' "$0" + printf 'usage: %s [-d|-x|-o] char\n' "$0" + printf '\t-d print number in decimal (default)\n' + printf '\t-x print number in hexadecimal\n' + printf '\t-o print number in octal\n' exit 1 fi -printf '%d\n' "\"$1\"" +printf "%${format}\n" "\"$1\"" |