A NOTE has been added to this issue. ====================================================================== http://austingroupbugs.net/view.php?id=1161 ====================================================================== Reported By: steffen Assigned To: ====================================================================== Project: 1003.1(2016)/Issue7+TC2 Issue ID: 1161 Category: Shell and Utilities Type: Clarification Requested Severity: Editorial Priority: normal Status: New Name: steffen Organization: User Reference: Section: command Page Number: 2596 Line Number: 84274 ff. Interp Status: --- Final Accepted Text: ====================================================================== Date Submitted: 2017-09-04 13:09 UTC Last Modified: 2017-09-05 16:01 UTC ====================================================================== Summary: command -v must find something executable ======================================================================
---------------------------------------------------------------------- (0003831) stephane (reporter) - 2017-09-05 16:01 http://austingroupbugs.net/view.php?id=1161#c3831 ---------------------------------------------------------------------- Re: http://austingroupbugs.net/view.php?id=1161#c3829 >> I never understood why i cannot say "IFS=: set -- $PATH", by the way, has >> anyone an answer for this? > > Because the standard says that variable assignments preceding a simple command > are processed after the command words are expanded. Also, one needs to disable globbing with "set -o noglob" or "set -f" which is the other effect of leaving that $PATH unquoted, and splitting $PATH that way is invalid as it splits "/bin:/usr/bin:" into "/bin", "/usr/bin" instead of "/bin", "/usr/bin" and "". One would also need to take care of the "" and "/" cases specially. And avoid echo Using: thecmd() ( IFS=: set -o noglob for p in $PATH''; do case $p in ("") file=$1;; (*/) file=$p$1;; (*) file=$p/$1;; esac if [ -f "$file" ] && [ -x "$file" ]; then printf '%s\n' "$file" exit 0 fi done printf >&2 '"%s" not found\n' "$1" exit 1 ) Should work in most POSIX-like shells (not in the Bourne shell obviously) Doesn't necessarily give you an executable file, but in the case of bash, would (I believe, it's been a long time since I looked into that) give you the one it would execute as long as euid==ruid (and report an error if it fails). Issue History Date Modified Username Field Change ====================================================================== 2017-09-04 13:09 steffen New Issue 2017-09-04 13:09 steffen Name => steffen 2017-09-04 13:09 steffen Section => command 2017-09-04 13:09 steffen Page Number => 2596 2017-09-04 13:09 steffen Line Number => 84274 ff. 2017-09-04 15:49 kre Note Added: 0003821 2017-09-05 06:58 stephane Note Added: 0003823 2017-09-05 08:30 stephane Note Added: 0003824 2017-09-05 12:34 steffen Note Added: 0003825 2017-09-05 12:39 steffen Note Added: 0003826 2017-09-05 12:47 kre Note Added: 0003827 2017-09-05 13:37 steffen Note Added: 0003828 2017-09-05 15:37 chet_ramey Note Added: 0003829 2017-09-05 15:41 stephane Note Added: 0003830 2017-09-05 16:01 stephane Note Added: 0003831 ======================================================================