This snippet detects various information about the shell script in which it is being executed. Copy and paste it into the top of your script.
Variables set are as follows:
$__SHELL
:bash
orzsh
$__SOURCED
:true
if the file was invoked usingsource filename
or. filename
, otherwise it will be blank.$__SCRIPT_PATH
: the full absolute path to the script.$__SCRIPT_DIR
: the full absolute path to the script's directory.$__SCRIPT_PATH_DEREFERENCED
: the full absolute path to the script, dereferencing all symbolic links.$__SCRIPT_DIR_DEREFERENCED
: the full absolute path to the script's directory, dereferencing all symbolic links.
If you change those
echo
statements toprintf %s "$1"
then you can remove the calls to.strip()
considering that they could erroneously remove legitimate whitespace.