How may I detect the name of the directory (or better yet the entire path) in which my shell script is run?
pwd (print working directory) – The pwd command is used to display the name of the current working directory in the Linux system using the terminal. This is a shell building command that is available in most Unix shells such as Bourne shell, ash, bash, kash, and zsh.
Print Current Working Directory ( pwd ) To print the name of the current working directory, use the command pwd . As this is the first command that you have executed in Bash in this session, the result of the pwd is the full path to your home directory.
what shell? What operating system?
For starters try
man pwd
$PWD
This, I believe, is the most portable way:
dir=$(cd -P -- "$(dirname -- "$0")" && pwd -P)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With