Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Answer

Post Timeline

Active reading [<https://en.wikipedia.org/wiki/Mac_OS_X_Snow_Leopard>]. Made compliant with the Jon Skeet Decree - <https://twitter.com/PeterMortensen/status/976400000942034944>.
Source Link
Peter Mortensen
  • 31.3k
  • 22
  • 110
  • 134

If there is noisn't any external type command available (as taken for granted here here), we can use POSIX compliant env -i sh -c 'type cmd 1>/dev/null 2>&1':

# portablePortable version of Bash's type -P cmd (without output on stdout)
typep() {
 command -p env -i PATH="$PATH" sh -c '
 export LC_ALL=C LANG=C
 cmd="1ドル"
 cmd="`type "$cmd" 2>/dev/null || { echo "error: command $cmd not found; exiting ..." 1>&2; exit 1; }`"
 [ $? != 0 ] && exit 1
 case "$cmd" in
 *\ /*) exit 0;;
 *) printf "%s\n" "error: $cmd" 1>&2; exit 1;;
 esac
 ' _ "1ドル" || exit 1
}
# getGet your standard $PATH value
#PATH="$(command -p getconf PATH)"
typep ls
typep builtin
typep ls-temp

At least on Mac OS X 10.6.8Mac OS X v10.6.8 (Snow Leopard) using Bash 4.2.24(2) command -v ls does not match a moved /bin/ls-temp.

If there is no external type command available (as taken for granted here), we can use POSIX compliant env -i sh -c 'type cmd 1>/dev/null 2>&1':

# portable version of Bash's type -P cmd (without output on stdout)
typep() {
 command -p env -i PATH="$PATH" sh -c '
 export LC_ALL=C LANG=C
 cmd="1ドル"
 cmd="`type "$cmd" 2>/dev/null || { echo "error: command $cmd not found; exiting ..." 1>&2; exit 1; }`"
 [ $? != 0 ] && exit 1
 case "$cmd" in
 *\ /*) exit 0;;
 *) printf "%s\n" "error: $cmd" 1>&2; exit 1;;
 esac
 ' _ "1ドル" || exit 1
}
# get your standard $PATH value
#PATH="$(command -p getconf PATH)"
typep ls
typep builtin
typep ls-temp

At least on Mac OS X 10.6.8 using Bash 4.2.24(2) command -v ls does not match a moved /bin/ls-temp.

If there isn't any external type command available (as taken for granted here), we can use POSIX compliant env -i sh -c 'type cmd 1>/dev/null 2>&1':

# Portable version of Bash's type -P cmd (without output on stdout)
typep() {
 command -p env -i PATH="$PATH" sh -c '
 export LC_ALL=C LANG=C
 cmd="1ドル"
 cmd="`type "$cmd" 2>/dev/null || { echo "error: command $cmd not found; exiting ..." 1>&2; exit 1; }`"
 [ $? != 0 ] && exit 1
 case "$cmd" in
 *\ /*) exit 0;;
 *) printf "%s\n" "error: $cmd" 1>&2; exit 1;;
 esac
 ' _ "1ドル" || exit 1
}
# Get your standard $PATH value
#PATH="$(command -p getconf PATH)"
typep ls
typep builtin
typep ls-temp

At least on Mac OS X v10.6.8 (Snow Leopard) using Bash 4.2.24(2) command -v ls does not match a moved /bin/ls-temp.

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link
URL Rewriter Bot
URL Rewriter Bot

If there is no external type command available (as taken for granted here here), we can use POSIX compliant env -i sh -c 'type cmd 1>/dev/null 2>&1':

# portable version of Bash's type -P cmd (without output on stdout)
typep() {
 command -p env -i PATH="$PATH" sh -c '
 export LC_ALL=C LANG=C
 cmd="1ドル" 
 cmd="`type "$cmd" 2>/dev/null || { echo "error: command $cmd not found; exiting ..." 1>&2; exit 1; }`"
 [ $? != 0 ] && exit 1
 case "$cmd" in
 *\ /*) exit 0;;
 *) printf "%s\n" "error: $cmd" 1>&2; exit 1;;
 esac
 ' _ "1ドル" || exit 1
}
# get your standard $PATH value
#PATH="$(command -p getconf PATH)"
typep ls
typep builtin
typep ls-temp

At least on Mac OS X 10.6.8 using Bash 4.2.24(2) command -v ls does not match a moved /bin/ls-temp.

If there is no external type command available (as taken for granted here), we can use POSIX compliant env -i sh -c 'type cmd 1>/dev/null 2>&1':

# portable version of Bash's type -P cmd (without output on stdout)
typep() {
 command -p env -i PATH="$PATH" sh -c '
 export LC_ALL=C LANG=C
 cmd="1ドル" 
 cmd="`type "$cmd" 2>/dev/null || { echo "error: command $cmd not found; exiting ..." 1>&2; exit 1; }`"
 [ $? != 0 ] && exit 1
 case "$cmd" in
 *\ /*) exit 0;;
 *) printf "%s\n" "error: $cmd" 1>&2; exit 1;;
 esac
 ' _ "1ドル" || exit 1
}
# get your standard $PATH value
#PATH="$(command -p getconf PATH)"
typep ls
typep builtin
typep ls-temp

At least on Mac OS X 10.6.8 using Bash 4.2.24(2) command -v ls does not match a moved /bin/ls-temp.

If there is no external type command available (as taken for granted here), we can use POSIX compliant env -i sh -c 'type cmd 1>/dev/null 2>&1':

# portable version of Bash's type -P cmd (without output on stdout)
typep() {
 command -p env -i PATH="$PATH" sh -c '
 export LC_ALL=C LANG=C
 cmd="1ドル" 
 cmd="`type "$cmd" 2>/dev/null || { echo "error: command $cmd not found; exiting ..." 1>&2; exit 1; }`"
 [ $? != 0 ] && exit 1
 case "$cmd" in
 *\ /*) exit 0;;
 *) printf "%s\n" "error: $cmd" 1>&2; exit 1;;
 esac
 ' _ "1ドル" || exit 1
}
# get your standard $PATH value
#PATH="$(command -p getconf PATH)"
typep ls
typep builtin
typep ls-temp

At least on Mac OS X 10.6.8 using Bash 4.2.24(2) command -v ls does not match a moved /bin/ls-temp.

prevent lookup of builtins from being a legal match (false positive)
Source Link

If there is no external type command available (as taken for granted here), we can use POSIX compliant env -i sh -c 'type cmd 1>/dev/null 2>&1':

# portable version of Bash's type -P cmd (without output on stdout)
typep() {
 command -p env -i PATH="$PATH" sh -c '
 cmd="1ドル" 
  export LC_ALL=C LANG=C
 type "$cmd" 1>/dev/null 2>&1 ||cmd="1ドル" 
 cmd="`type "$cmd" 2>/dev/null || { echo "command"error: command $cmd not found; exiting ..." 1>&2; exit 1; }`"
 [ $? != 0 ] && exit 1
 case "$cmd" in
 *\ /*) exit 0;;
 *) printf "%s\n" "error: $cmd" 1>&2; exit 1;;
 esac
 ' _ "1ドル" || exit 1
}
# get your standard $PATH value
#PATH="$(command -p getconf PATH)"
typep ls
typep builtin
typep ls-temp

At least on Mac OS X 10.6.8 using Bash 4.2.24(2) command -v ls does not match a moved /bin/ls-temp.

If there is no external type command available (as taken for granted here), we can use POSIX compliant env -i sh -c 'type cmd 1>/dev/null 2>&1':

# portable version of Bash's type -P cmd
typep() {
 command -p env -i PATH="$PATH" sh -c '
 cmd="1ドル" 
  type "$cmd" 1>/dev/null 2>&1 || 
 { echo "command $cmd not found; exiting ..." 1>&2; exit 1; }
 ' _ "1ドル" || exit 1
}
# get your standard $PATH value
#PATH="$(command -p getconf PATH)"
typep ls
typep ls-temp

At least on Mac OS X 10.6.8 using Bash 4.2.24(2) command -v ls does not match a moved /bin/ls-temp.

If there is no external type command available (as taken for granted here), we can use POSIX compliant env -i sh -c 'type cmd 1>/dev/null 2>&1':

# portable version of Bash's type -P cmd (without output on stdout)
typep() {
 command -p env -i PATH="$PATH" sh -c '
 export LC_ALL=C LANG=C
 cmd="1ドル" 
 cmd="`type "$cmd" 2>/dev/null || { echo "error: command $cmd not found; exiting ..." 1>&2; exit 1; }`"
 [ $? != 0 ] && exit 1
 case "$cmd" in
 *\ /*) exit 0;;
 *) printf "%s\n" "error: $cmd" 1>&2; exit 1;;
 esac
 ' _ "1ドル" || exit 1
}
# get your standard $PATH value
#PATH="$(command -p getconf PATH)"
typep ls
typep builtin
typep ls-temp

At least on Mac OS X 10.6.8 using Bash 4.2.24(2) command -v ls does not match a moved /bin/ls-temp.

Source Link
Loading
lang-bash

AltStyle によって変換されたページ (->オリジナル) /