1. Get the name of the shell script
${BASH_SOURCE-$0}
2. Get the path to the shell script
DirName "${bash_source-$0}"
This path is not necessarily the true path of the script, for example, assuming that the command is in file/home/hubavyn/test.sh.
Perform the following actions:
CD/HOME/HUBAVYN/A (Suppose A is a folder)
Sh.. /test.sh (this time execute the above dirname command to get the result just ...)
And if you want to get the true path of the script (/home/hubavyn), do the following:
Path= ' DirName "" ${bash_source-$0} '
Real_path= ' CD ' Path ' >/dev/null;pwd '
This is the time to get Real_path is/home/hubavyn. The benefit is that the script can be deployed flexibly, and it is easy to get the location of other files deployed with the script.
3. Add in a script. < The name of another script >
Plus. Indicates that another script is equivalent to executing in the current script, such as a variable assignment in another script, as well as in the current script.
Learn the shell bit by bit