-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).

  • 3
    Possible duplicate of [How can I get the current working directory?](https://unix.stackexchange.com/questions/188182/how-can-i-get-the-current-working-directory) Or more exactly: [Get directory from which script was called from](https://unix.stackexchange.com/questions/52916/get-directory-from-which-script-was-called-from) – muru Jun 18 '19 at 08:03
  • 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 '19 at 08: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 '19 at 08:58
  • @Kamil Maciorowski yes exactly... I need a command to use outside of the script. – Rajan Sharma Jun 18 '19 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 '19 at 11:25

1 Answers1

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.

dr_
  • 28,763
  • 21
  • 89
  • 133
  • 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 '19 at 08: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. – dr_ Jun 18 '19 at 09:11