Grabs the location and name of the script file itself.
Get current scripts path/location and name.
#!/bin/bash
# Example of how to get script file/path info.
# -chriswelborn
# This will work even if the script is symlinked
# and called from another directory.
# It does not show the CWD (current working dir),
# but the location of this script itself.
scriptreal="${BASH_SOURCE[0]}"
scriptpath="$(realpath $scriptreal)"
scriptdir="$(dirname $scriptpath)"
scriptname="$(basename $scriptpath)"
echo "Real:"
echo " path: $scriptpath"
echo " dir: $scriptdir"
echo " name: $scriptname"
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.