You can get the current directory in a shell script using the pwd
command. However, it’s recommended to use the $PWD
shell variable, which is automatically set to the current working directory.
Here’s an example shell script that prints the current directory:
echo "Current directory: $PWD"
You can also use the $(pwd)
command substitution to get the current directory:
echo "Current directory: $(pwd)"