diff --git a/sh/witch b/sh/witch index 366d82e..d24879f 100755 --- a/sh/witch +++ b/sh/witch @@ -4,10 +4,11 @@ ### this is a personal rewrite of `which` from Debian. ### the original version didn't run on certain shells, ### and inherited inconsistent behaviors from getopts. +### the silent (`-s`) flag from Ubuntu has been added. set -ef -all=0 +all=0 silent=0 for flag; do case "$flag" in (--) shift; break;; @@ -16,6 +17,7 @@ for flag; do while flag="${flag#?}"; [ -n "$flag" ]; do case "$flag" in (a*) all=1;; + (s*) silent=1;; (*) printf >&2 'Illegal option: -%.1s\n' "$flag" printf 'Usage: %s\n' "$0 [-a] args" @@ -28,13 +30,19 @@ done [ "$#" = 0 ] && res=1 || res=0 +if [ "$silent" = 0 ]; then + puts() { printf %s\\n "$@"; } +else + puts() { :; } +fi + IFS=: for prog; do err=1 case "$prog" in (*/*) if [ -f "$prog" ] && [ -x "$prog" ]; then - printf %s\\n "$prog" + puts "$prog" err=0 fi;; (*) @@ -42,7 +50,7 @@ for prog; do for sub; do [ -n "$sub" ] || sub=. if [ -f "$sub/$prog" ] && [ -x "$sub/$prog" ]; then - printf %s\\n "$sub/$prog" + puts "$sub/$prog" err=0 [ "$all" = 1 ] || break fi