Skip to content

Instantly share code, notes, and snippets.

@zfenj
Created June 12, 2019 08:30
Show Gist options
  • Select an option

  • Save zfenj/af9627b22450c5080f8428ba341f5298 to your computer and use it in GitHub Desktop.

Select an option

Save zfenj/af9627b22450c5080f8428ba341f5298 to your computer and use it in GitHub Desktop.
# Source: https://unix.stackexchange.com/a/115431
#!/usr/bin/env zsh
# only file- / script name
echo ${0:a}
#!/usr/bin/env zsh
# file- / script name with path
echo ${0:a:h}
@dmarmor
Copy link

dmarmor commented Dec 9, 2025

Both of these examples are incorrect.

${0:a} = absolute script path (as run, not the canonical path)
${0:a:h} = same, but only the script's enclosing directory (stripping off the actual script name)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment