summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Kaivo <jkk@ung.org>2019-08-14 13:34:14 -0400
committerJakob Kaivo <jkk@ung.org>2019-08-14 13:34:14 -0400
commitbbad39de0ef340032cac0698c399509dca929c44 (patch)
tree99fc87b7562f00b9166142739c8a60d870085cca
parent07602b5ed3b84129d756373e861d9d19be578de4 (diff)
add support for hex and octal output
-rw-r--r--ord.sh18
1 files changed, 16 insertions, 2 deletions
diff --git a/ord.sh b/ord.sh
index 97e96f3..fac6b09 100644
--- a/ord.sh
+++ b/ord.sh
@@ -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\""