I have a script doSmth in /usr/bin. Is it possible to print the directory the script was called from is printed out by the script?
So If I call doSmth from /home/me the output will be /home/me.
|
|
When you invoke a command in the shell, the new process inherits the working directory of the parent. Here are two ways get the working directory:
|
|||
|
|
|
By "directory it was called from" you seem to mean its working directory. You can change this inside the script using e.g., If you'll need the initial working directory after changing it, just save it at the top of your script (before changing it)
If you're using this to get back to the directory you started in, see also |
|||||||||
|