3 added 1 character in body
source | link

You can find out what directory the script is in ($0:h in zsh, "${0%/*}" in sh) and remove that directory from PATH (path=(${path:#$0:h}) in zsh, more complicatedincomplicated in sh. This could fail if PATH contains the same directory twice, e.g. through a symbolic link.

A downside of the straight approach is that this removes the directory from the path, but other programs in the same directory might be desirable. You can solve this issue by doing only the path lookup with a modified path.

next=$(path=(${path:#$0:h}); print -lr -- =$0:t)
$next

Instead I'd do the PATH lookup manually and skip any occurrence of the running script.

for d in $path; do
  if [[ -x $d/$0:t && ! $d/$0:t -ef $0 ]]; then
    exec $d/$0:t
  fi
done

You can find out what directory the script is in ($0:h in zsh, "${0%/*}" in sh) and remove that directory from PATH (path=(${path:#$0:h}) in zsh, more complicatedin sh. This could fail if PATH contains the same directory twice, e.g. through a symbolic link.

A downside of the straight approach is that this removes the directory from the path, but other programs in the same directory might be desirable. You can solve this issue by doing only the path lookup with a modified path.

next=$(path=(${path:#$0:h}); print -lr -- =$0:t)
$next

Instead I'd do the PATH lookup manually and skip any occurrence of the running script.

for d in $path; do
  if [[ -x $d/$0:t && ! $d/$0:t -ef $0 ]]; then
    exec $d/$0:t
  fi
done

You can find out what directory the script is in ($0:h in zsh, "${0%/*}" in sh) and remove that directory from PATH (path=(${path:#$0:h}) in zsh, more complicated in sh. This could fail if PATH contains the same directory twice, e.g. through a symbolic link.

A downside of the straight approach is that this removes the directory from the path, but other programs in the same directory might be desirable. You can solve this issue by doing only the path lookup with a modified path.

next=$(path=(${path:#$0:h}); print -lr -- =$0:t)
$next

Instead I'd do the PATH lookup manually and skip any occurrence of the running script.

for d in $path; do
  if [[ -x $d/$0:t && ! $d/$0:t -ef $0 ]]; then
    exec $d/$0:t
  fi
done
2 typo (thanks woky)
source | link

You can find out what directory the script is in ($0:h in zsh, "${0%/*}" in sh) and remove that directory from PATH (path=(${path:#$0:h}) in zsh, more complicatedin sh. This could fail if PATH contains the same directory twice, e.g. through a symbolic link.

A downside of the straight approach is that this removes the directory from the path, but other programs in the same directory might be desirable. You can solve this issue by doing only the path lookup with a modified path.

next=$(path=(${path:#$0:h}); print -lr -- =$0:ht)
$next

Instead I'd do the PATH lookup manually and skip any occurrence of the running script.

for d in $path; do
  if [[ -x $d/$0:t && ! $d/$0:t -ef $0 ]]; then
    exec $d/$0:t
  fi
done

You can find out what directory the script is in ($0:h in zsh, "${0%/*}" in sh) and remove that directory from PATH (path=(${path:#$0:h}) in zsh, more complicatedin sh. This could fail if PATH contains the same directory twice, e.g. through a symbolic link.

A downside of the straight approach is that this removes the directory from the path, but other programs in the same directory might be desirable. You can solve this issue by doing only the path lookup with a modified path.

next=$(path=(${path:#$0:h}); print -lr -- =$0:h)
$next

Instead I'd do the PATH lookup manually and skip any occurrence of the running script.

for d in $path; do
  if [[ -x $d/$0:t && ! $d/$0:t -ef $0 ]]; then
    exec $d/$0:t
  fi
done

You can find out what directory the script is in ($0:h in zsh, "${0%/*}" in sh) and remove that directory from PATH (path=(${path:#$0:h}) in zsh, more complicatedin sh. This could fail if PATH contains the same directory twice, e.g. through a symbolic link.

A downside of the straight approach is that this removes the directory from the path, but other programs in the same directory might be desirable. You can solve this issue by doing only the path lookup with a modified path.

next=$(path=(${path:#$0:h}); print -lr -- =$0:t)
$next

Instead I'd do the PATH lookup manually and skip any occurrence of the running script.

for d in $path; do
  if [[ -x $d/$0:t && ! $d/$0:t -ef $0 ]]; then
    exec $d/$0:t
  fi
done
1
source | link

You can find out what directory the script is in ($0:h in zsh, "${0%/*}" in sh) and remove that directory from PATH (path=(${path:#$0:h}) in zsh, more complicatedin sh. This could fail if PATH contains the same directory twice, e.g. through a symbolic link.

A downside of the straight approach is that this removes the directory from the path, but other programs in the same directory might be desirable. You can solve this issue by doing only the path lookup with a modified path.

next=$(path=(${path:#$0:h}); print -lr -- =$0:h)
$next

Instead I'd do the PATH lookup manually and skip any occurrence of the running script.

for d in $path; do
  if [[ -x $d/$0:t && ! $d/$0:t -ef $0 ]]; then
    exec $d/$0:t
  fi
done