-2

suppose there is a script "/home/abc/test.go". Someone else went to another directory lets assume "/etc/random/" and executed the script "test.go".

Now I want to know from where the script was invoked.

Can anyone help me with the command to know from where the script was invoked(/etc/random/)??

I tried "lsof" but it gives the files that the script is working on and the location of the script(/home/abc/) but not from where it is invoked.

Note:- I don't want to use $pwd in the script. I am looking for a command that can just display the directory from where the mentioned script was executed(invoked).

marked as duplicate by muru, user4556274, Prvt_Yadv, msp9011, Fabby Jun 24 at 18:43

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 3
  • No, i have checked those and my question is completely different. I want to know from which directory the script was executed. – Rajan Sharma Jun 18 at 8:54
  • You could use the phrase "find the current working directory of the shell that invoked the script" to avoid any misinterpretation of your question. – Kusalananda Jun 18 at 8:58
  • @Kamil Maciorowski yes exactly... I need a command to use outside of the script. – Rajan Sharma Jun 18 at 11:17
  • Please make it clear in the question itself. When you say "without using $pwd in my script" the first thought is you want to use something else in the script. – Kamil Maciorowski Jun 18 at 11:25
1

The current directory is stored in the variable $PWD.

You could store that value somewhere at the beginning of the script to e.g. output it or save it in a log.

  • The script is executed by another user and We can't modify the script As an admin, I Just want to know the directory from where he executed the script I mean is there a general command to find that...?? – Rajan Sharma Jun 18 at 8:52
  • No, there isn't, unless you set up a complete audit system. You could also have a look at the user's shell history. – dr01 Jun 18 at 9:11

Not the answer you're looking for? Browse other questions tagged or ask your own question.