Skip to main content
added 1 character in body
Source Link
Stéphane Chazelas
  • 586.9k
  • 96
  • 1.1k
  • 1.7k

(if it doesn't contain a she-bang, or more generally if the system returns a ENOEXEC error, then itsit's your shell that will do the same thing)

(if it doesn't contain a she-bang, or more generally if the system returns a ENOEXEC error, then its your shell that will do the same thing)

(if it doesn't contain a she-bang, or more generally if the system returns a ENOEXEC error, then it's your shell that will do the same thing)

deleted 185 characters in body
Source Link
Stéphane Chazelas
  • 586.9k
  • 96
  • 1.1k
  • 1.7k
progname=$0
[ -r "$progname" ] || progname=$(
    PATH_terminated=${PATH-$(getconf PATH)}:
    IFS=:; set -f
    for i in $PATH_terminated;${PATH-$(getconf PATH)}""; do
      case $i in
        "") p=$progname;;
        */) p=$i$progname;;
        *) p=$i/$progname
      esac
      [ -r "$p" ] && exec printf '%s\n' "$p"
    done
    exit 1
  ) && progname=$(readlink -e -- "$progname") ||
  progname=unknown

(here assuming a POSIX shell where IFS is the field delimiter. Shells likethe zsh"" (inappended to sh$PATH emulation) or olderis to preserve a trailing empty element with shells whose pdksh$IFS-based ones that treat IFS acts as a field separatordelimiter will see an extra empty element in the splittinginstead of $PATH_terminatedseparator).

progname=$0
[ -r "$progname" ] || progname=$(
    PATH_terminated=${PATH-$(getconf PATH)}:
    IFS=:; set -f
    for i in $PATH_terminated;${PATH-$(getconf PATH)}:; do
      case $i in
        "") p=$progname;;
        */) p=$i$progname;;
        *) p=$i/$progname
      esac
      [ -r "$p" ] && exec printf '%s\n' "$p"
    done
    exit 1
  ) && progname=$(readlink -e -- "$progname") ||
  progname=unknown

[ -f "$progname" ] && grep -q 7YQLVVD3UIUDTA32LSE8U9UOHH < "$progname" ||
  progname=unknown
progname=$0
[ -r "$progname" ] || progname=$(
    PATH_terminated=${PATH-$(getconf PATH)}:
    IFS=:; set -f
    for i in $PATH_terminated; do
      case $i in
        "") p=$progname;;
        */) p=$i$progname;;
        *) p=$i/$progname
      esac
      [ -r "$p" ] && exec printf '%s\n' "$p"
    done
    exit 1
  ) && progname=$(readlink -e -- "$progname") ||
  progname=unknown

(here assuming a POSIX shell where IFS is the field delimiter. Shells like zsh (in sh emulation) or older pdksh-based ones that treat IFS as a field separator will see an extra empty element in the splitting of $PATH_terminated).

progname=$0
[ -r "$progname" ] || progname=$(
    PATH_terminated=${PATH-$(getconf PATH)}:
    IFS=:; set -f
    for i in $PATH_terminated; do
      case $i in
        "") p=$progname;;
        */) p=$i$progname;;
        *) p=$i/$progname
      esac
      [ -r "$p" ] && exec printf '%s\n' "$p"
    done
    exit 1
  ) && progname=$(readlink -e -- "$progname") ||
  progname=unknown

[ -f "$progname" ] && grep -q 7YQLVVD3UIUDTA32LSE8U9UOHH < "$progname" ||
  progname=unknown
progname=$0
[ -r "$progname" ] || progname=$(
    IFS=:; set -f
    for i in ${PATH-$(getconf PATH)}""; do
      case $i in
        "") p=$progname;;
        */) p=$i$progname;;
        *) p=$i/$progname
      esac
      [ -r "$p" ] && exec printf '%s\n' "$p"
    done
    exit 1
  ) && progname=$(readlink -e -- "$progname") ||
  progname=unknown

(the "" appended to $PATH is to preserve a trailing empty element with shells whose $IFS acts as delimiter instead of separator).

progname=$0
[ -r "$progname" ] || progname=$(
    IFS=:; set -f
    for i in ${PATH-$(getconf PATH)}:; do
      case $i in
        "") p=$progname;;
        */) p=$i$progname;;
        *) p=$i/$progname
      esac
      [ -r "$p" ] && exec printf '%s\n' "$p"
    done
    exit 1
  ) && progname=$(readlink -e -- "$progname") ||
  progname=unknown

[ -f "$progname" ] && grep -q 7YQLVVD3UIUDTA32LSE8U9UOHH < "$progname" ||
  progname=unknown
/bin:/usr/bin: would be treated as "/bin", "/usr/bin" in POSIX shells instead of "/bin", "/usr/bin" and "".
Source Link
Stéphane Chazelas
  • 586.9k
  • 96
  • 1.1k
  • 1.7k
progname=$0
[ -r "$progname" ] || progname=$(
    PATH_terminated=${PATH-$(getconf PATH)}:
    IFS=:; set -f
    for i in ${PATH-$(getconf PATH)};$PATH_terminated; do
      case $i in
        "") p=$progname;;
        */) p=$i$progname;;
        *) p=$i/$progname
      esac
      [ -r "$p" ] && exec printf '%s\n' "$p"
    done
    exit 1
  ) && progname=$(readlink -e -- "$progname") ||
  progname=unknown

(here assuming a POSIX shell where IFS is the field delimiter. Shells like zsh (in sh emulation) or older pdksh-based ones that treat IFS as a field separator will see an extra empty element in the splitting of $PATH_terminated).

progname=$0
[ -r "$progname" ] || progname=$(
    PATH_terminated=${PATH-$(getconf PATH)}:
    IFS=:; set -f
    for i in ${PATH-$(getconf PATH)};$PATH_terminated; do
      case $i in
        "") p=$progname;;
        */) p=$i$progname;;
        *) p=$i/$progname
      esac
      [ -r "$p" ] && exec printf '%s\n' "$p"
    done
    exit 1
  ) && progname=$(readlink -e -- "$progname") ||
  progname=unknown

[ -f "$progname" ] && grep -q 7YQLVVD3UIUDTA32LSE8U9UOHH < "$progname" ||
  progname=unknown
progname=$0
[ -r "$progname" ] || progname=$(
    IFS=:; set -f
    for i in ${PATH-$(getconf PATH)}; do
      case $i in
        "") p=$progname;;
        */) p=$i$progname;;
        *) p=$i/$progname
      esac
      [ -r "$p" ] && exec printf '%s\n' "$p"
    done
    exit 1
  ) && progname=$(readlink -e -- "$progname") ||
  progname=unknown
progname=$0
[ -r "$progname" ] || progname=$(
    IFS=:; set -f
    for i in ${PATH-$(getconf PATH)}; do
      case $i in
        "") p=$progname;;
        */) p=$i$progname;;
        *) p=$i/$progname
      esac
      [ -r "$p" ] && exec printf '%s\n' "$p"
    done
    exit 1
  ) && progname=$(readlink -e -- "$progname") ||
  progname=unknown

[ -f "$progname" ] && grep -q 7YQLVVD3UIUDTA32LSE8U9UOHH < "$progname" ||
  progname=unknown
progname=$0
[ -r "$progname" ] || progname=$(
    PATH_terminated=${PATH-$(getconf PATH)}:
    IFS=:; set -f
    for i in $PATH_terminated; do
      case $i in
        "") p=$progname;;
        */) p=$i$progname;;
        *) p=$i/$progname
      esac
      [ -r "$p" ] && exec printf '%s\n' "$p"
    done
    exit 1
  ) && progname=$(readlink -e -- "$progname") ||
  progname=unknown

(here assuming a POSIX shell where IFS is the field delimiter. Shells like zsh (in sh emulation) or older pdksh-based ones that treat IFS as a field separator will see an extra empty element in the splitting of $PATH_terminated).

progname=$0
[ -r "$progname" ] || progname=$(
    PATH_terminated=${PATH-$(getconf PATH)}:
    IFS=:; set -f
    for i in $PATH_terminated; do
      case $i in
        "") p=$progname;;
        */) p=$i$progname;;
        *) p=$i/$progname
      esac
      [ -r "$p" ] && exec printf '%s\n' "$p"
    done
    exit 1
  ) && progname=$(readlink -e -- "$progname") ||
  progname=unknown

[ -f "$progname" ] && grep -q 7YQLVVD3UIUDTA32LSE8U9UOHH < "$progname" ||
  progname=unknown
typos
Source Link
Stéphane Chazelas
  • 586.9k
  • 96
  • 1.1k
  • 1.7k
Loading
Source Link
Stéphane Chazelas
  • 586.9k
  • 96
  • 1.1k
  • 1.7k
Loading