in Software by (9.9k points)
0 like 0 dislike
13 views

How I can to dynamically get path to current directory in bash? How to save current directory in variable using bash? What I'm trying to do is find the current working directory and save it into a variable. How do I save the current directory in variable using bash script? How can I get the current working directory?


bash current dir variable

1 Answer

0 like 0 dislike
by (9.9k points)

This saves the absolute path of current working directory to the variable dir:

dir=$(pwd)

Function:

function mark {
    export $1=`pwd`;
}

Current working directory variable, i.e. full path:

dir=$PWD

Print full path:

echo $dir

Your answer

Try to answer the question as detailed as possible.
Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.