Contents
How do you find the real path?
To get physical path use realpath command. The realpath command uses the realpath() function to resolve all symbolic links, extra / characters and references to /./ and /../ in path. This is useful for shell scripting and security related applications.
How do I add a script to my path?
4 Answers
- Save the script as apt-proxy (without the . sh extension) in some directory, like ~/bin .
- Add ~/bin to your PATH , typing export PATH=$PATH:~/bin.
- If you need it permanently, add that last line in your ~/. bashrc .
- Then you can just run apt-proxy with your arguments and it will run anywhere.
How to get path of initially run script?
For script run under web server $_SERVER [‘SCRIPT_FILENAME’] will contain the full path to the initially called script, so probably your index.php. realpath () is not required in this case. For the script run from console $_SERVER [‘SCRIPT_FILENAME’] will contain relative path to your initially called script from your current working dir.
How to get the absolute path of a script?
A simple way to have the absolute path of the initially executed script, in that script and any other script included with include, require, require_once is by using a constant and storing there the current script path at beginning of the main script:
Where to find the script name and path?
Now there can be two posible situation where the script is located in some directory under a symlink or it is located under physical path. Now for both situation the variable will vary Lastly I hope the steps from the article to get script name and script path from within the shell script on Linux was helpful.
How to get the path of the parent script?
If you place this in an included file, it prints the path to this include. To get the path of the parent script, replace __FILE__ with $_SERVER [‘PHP_SELF’]. But be aware that PHP_SELF is a security risk! The directory of the file. If used inside an include, the directory of the included file is returned.