The method of obtaining the real path of the current script by Linux
1. Get the real path of the current script:
#! / bin/bashif [[$0 = ~ ^\ / .*] # determine whether the current script is an absolute path, and match all then script=$0else script=$ (pwd) / $0fiscript = `readlink-f $script` # starting with / to get the real path of the file script_path=$ {script%/*} # get the directory where the file is located realpath=$ (readlink-f $script_path) # get the real path of the directory echo $scriptecho $script_pathecho $realpath
2.readlink-f: get the real file location of the symbolic link, and finally get the real file location of the symbolic link
3.basename: gets the file name of the file
4.dirname: gets the directory name of the file
Summary
The above is the whole content of this article. I hope the content of this article has a certain reference and learning value for everyone's study or work. Thank you for your support. If you want to know more about it, please see the relevant links below.