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?
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.
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.
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.
myvar="$PWD" cd "$myvar"
(Quotes are necessary if your path contains whitespaces.)
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