Is there a way to store a filename in a variable where the variable argument is written? Instead of hardcoding the filename, i would want the variable to know which file its in and store the name of the file in a variable.
dirname $0 will give the directory relative to how it was called, so you need to get the expanded path like this:
FULLPATH=$( cd $(dirname $0); pwd)
basename $0 will give the shell script name so
SHORTNAME=$(basename $0)
$FULLPATH/$SHORTNAME # is the fully qualified location of the current script.
The full path name is discussed as the most frequent bash question: Getting the source directory of a Bash script from within
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.