Skip to content

Instantly share code, notes, and snippets.

@dave-burke
Created July 24, 2014 19:16
Show Gist options
  • Save dave-burke/e671ddbb2622481ea4de to your computer and use it in GitHub Desktop.
Save dave-burke/e671ddbb2622481ea4de to your computer and use it in GitHub Desktop.
Demo of filename parsing in Bash
#!/bin/bash
echo "\${0} = ${0}"
echo "dirname \${0} = `dirname ${0}`"
echo "basename \${0} = `basename ${0}`"
echo "readlink -m \${0} = `readlink -m ${0}`" #In BSD (maybe not with -m option, though)
echo "realpath -m \${0} = `realpath -m ${0}`" #Easy to remember
echo "\$(cd \$(dirname \${0}); pwd)/\$(basename ${0}) = $(cd $(dirname ${0}); pwd)/$(basename ${0})" #Should be truly cross-platform
echo "\${0/%.sh/.foo} = ${0/%.sh/.foo}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment