Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting current path in variable and using it

Tags:

linux

bash

I would like to extract the current path in a variable and use it later on in the script

Something like:

myvar = pwd 

Later on:

cd myvar 

But my bash skills have rusted over the years.

How would i go on about doing that?

like image 674
R0b0tn1k Avatar asked Oct 28 '09 10:10

R0b0tn1k


People also ask

How do you find current PATH variable?

Display your path environment variable.Type echo $PATH at the command prompt and press ↵ Enter . This output is a list of directories where executable files are stored. If you try to run a file or command that isn't in one of the directories in your path, you'll receive an error that says the command is not found.

How do I get current path in bash?

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.

How do I echo the current directory in Linux?

To display the current working directory, we use the pwd command in the Linux/Unix system as shown below. To display the physical directory instead of symbolic links or soft links, we use -P option with the pwd command in the Linux/Unix system as shown below.


1 Answers

myvar="$PWD" cd "$myvar" 

(Quotes are necessary if your path contains whitespaces.)

like image 94
digitalarbeiter Avatar answered Oct 01 '22 21:10

digitalarbeiter