To get the absolute path of the executing program/script itself, you can use DirName (Realpath (__file__) in PHP, and C # has System.Windows.Forms.Application.StartupPath; Java does not seem to have any more direct method, can only use Codesource to gain indirectly. In a Linux shell script, if you want the absolute path of the current script file, there's no out-of-the-box command to call, but you can get it by using the following statement:
Copy Code code as follows:
basedirforscriptself=$ (CD "$ (dirname" $) "; pwd)
echo "full path to currently executed script is: ${basedirforscriptself}"
Although most of the cases do not require such an absolute path to complete the work, but if you want to pack more than one script, data files, and other content as a whole to deliver others to use, but also want to no matter what directory Users copy to execute the script can correctly find the other contents of the package, Using such a script to automatically locate the root of a package should be a relatively robust approach.