refined "usage:" error message
authorgit <redacted>
Sun, 15 Feb 2026 12:46:28 +0000 (07:46 -0500)
committergit <redacted>
Sun, 15 Feb 2026 12:46:28 +0000 (07:46 -0500)
tobin
todec
tohex

diff --git a/tobin b/tobin
index d9e6830b898133d60f967908191dc57319469390..58c0eae07f7fe70e6e3b6448d72717d8cae4c51c 100755 (executable)
--- a/tobin
+++ b/tobin
@@ -28,6 +28,7 @@ conv() {
 
 
 main() {
+       USAGE="usage: tobin [-mnp] ..."
        if ! [ "$1" = "x" ] && ! [ -t 0 ]; then
                cat | tr '\n' ' ' | xargs tobin "x" "$@"
                return "$?"
@@ -38,7 +39,7 @@ main() {
        fi
        
        if [ $# -eq 0 ]; then
-               printf "Error: No arguments provided\nusage: tobin [-mnp] number1 number2 ...\n" >&2
+               printf "Error: No arguments provided\n%s\n" "$USAGE" >&2
                return 2
 
        fi
@@ -50,7 +51,7 @@ main() {
                        m) m=1; ;;
                        n) n=1; ;;
                        p) p="0b" ;;
-                       *) printf "usage: tobin [-mnp] number1 number2 ...\n" >&2 ; return 2 ;;
+                       *) printf "%s\n" "$USAGE" >&2 ; return 2 ;;
                esac
        done
 
diff --git a/todec b/todec
index d48311dcc687249e017648cf31fafaf6d1abc0d6..feaff7efe354f721517ebc4fabd57c11e9c86ed3 100755 (executable)
--- a/todec
+++ b/todec
@@ -28,6 +28,7 @@ conv() {
 
 
 main() {
+       USAGE="usage: todec [-mnKMG] ..."
        if ! [ "$1" = "x" ] && ! [ -t 0 ]; then
                cat | tr '\n' ' ' | xargs todec "x" "$@"
                return "$?"
@@ -38,7 +39,7 @@ main() {
        fi
        
        if [ $# -eq 0 ]; then
-               printf "Error: No arguments provided\nusage: todec [-mn] number1 number2 ...\n" >&2
+               printf "Error: No arguments provided\n%s\n" "$USAGE" >&2
                return 2
 
        fi
@@ -55,7 +56,7 @@ main() {
                        M) k=100000000000000000000; p='M'; ;;
                        # 1 073 741 824
                        G) k=1000000000000000000000000000000; p='G'; ;;
-                       *) printf "usage: todec [-mnKMG] number1 number2 ...\n" >&2 ; return 2 ;;
+                       *) printf "%s\n" "$USAGE" >&2 ; return 2 ;;
                esac
        done
 
diff --git a/tohex b/tohex
index e27240514eb67370e220d364dca76d4398653311..0452e918641250aa7c4d8b65c7757f4a3676a260 100755 (executable)
--- a/tohex
+++ b/tohex
@@ -28,6 +28,7 @@ conv() {
 
 
 main() {
+       USAGE="usage: tohex [-lmnp] ..."
        if ! [ "$1" = "x" ] && ! [ -t 0 ]; then
                cat | tr '\n' ' ' | xargs tohex "x" "$@"
                return "$?"
@@ -38,7 +39,7 @@ main() {
        fi
        
        if [ $# -eq 0 ]; then
-               printf "Error: No arguments provided\nusage: tohex [-lmnp] number1 number2 ...\n" >&2
+               printf "Error: No arguments provided\n%s\n" "$USAGE" >&2
                return 2
 
        fi
@@ -51,7 +52,7 @@ main() {
                        m) m=1; ;;
                        n) n=1; ;;
                        p) p="0x" ;;
-                       *) printf "usage: tohex [-lmnp] number1 number2 ...\n" >&2 ; return 2 ;;
+                       *) printf "%s\n" "$USAGE" >&2 ; return 2 ;;
                esac
        done