summaryrefslogtreecommitdiffstats
path: root/scratch/bash-3.1/examples/functions/which
diff options
context:
space:
mode:
authorPete Travis <immanetize@fedoraproject.org>2014-09-26 14:42:22 -0600
committerPete Travis <immanetize@fedoraproject.org>2014-09-26 14:42:22 -0600
commit46c50fce0354d81d347a8055314a688fc8aa9f52 (patch)
treeb7f6c49e1225f949a9c21da6afa52fd04a2484fd /scratch/bash-3.1/examples/functions/which
parentfe5673aed2053463a7164ec5e7b609877340c0fa (diff)
downloadrpmbuild-46c50fce0354d81d347a8055314a688fc8aa9f52.tar.gz
rpmbuild-46c50fce0354d81d347a8055314a688fc8aa9f52.tar.xz
rpmbuild-46c50fce0354d81d347a8055314a688fc8aa9f52.zip
bash sourcesobs-product
Diffstat (limited to 'scratch/bash-3.1/examples/functions/which')
-rw-r--r--scratch/bash-3.1/examples/functions/which44
1 files changed, 44 insertions, 0 deletions
diff --git a/scratch/bash-3.1/examples/functions/which b/scratch/bash-3.1/examples/functions/which
new file mode 100644
index 0000000..ca33703
--- /dev/null
+++ b/scratch/bash-3.1/examples/functions/which
@@ -0,0 +1,44 @@
+#
+# which - emulation of `which' as it appears in FreeBSD
+#
+# usage: which [-as] command [command...]
+#
+
+which()
+{
+ local aflag sflag ES a opt
+
+ OPTIND=1
+ while builtin getopts as opt ; do
+ case "$opt" in
+ a) aflag=-a ;;
+ s) sflag=1 ;;
+ ?) echo "which: usage: which [-as] command [command ...]" >&2
+ exit 2 ;;
+ esac
+ done
+
+ (( $OPTIND > 1 )) && shift $(( $OPTIND - 1 ))
+
+ # without command arguments, exit with status 1
+ ES=1
+
+ # exit status is 0 if all commands are found, 1 if any are not found
+ for command; do
+ # if $command is a function, make sure we add -a so type
+ # will look in $PATH after finding the function
+ a=$aflag
+ case "$(builtin type -t $command)" in
+ "function") a=-a;;
+ esac
+
+ if [ -n "$sflag" ]; then
+ builtin type -p $a $command >/dev/null 2>&1
+ else
+ builtin type -p $a $command
+ fi
+ ES=$?
+ done
+
+ return $ES
+}