The current working directory is conveniently stored in the variable $PWD which is available in all POSIX compliant shells. Another option to get the current working directory is by using the pwd command. That pwd command is a shell builtin and available in all POSIX compliant shells as well.
$$ is a Bash internal variable that contains the Process ID (PID) of the shell running your script. Sometimes the $$ variable gets confused with the variable $BASHPID that contains the PID of the current Bash shell.
The easiest way to set environment variables in Bash is to use the “export” keyword followed by the variable name, an equal sign and the value to be assigned to the environment variable.
This saves the absolute path of the current working directory to the variable cwd
:
cwd=$(pwd)
In your case you can just do:
export PATH=$PATH:$(pwd)+somethingelse
I have the following in my .bash_profile:
function mark {
export $1=`pwd`;
}
so anytime I want to remember a directory, I can just type, e.g. mark there .
Then when I want to go back to that location, I just type cd $there
Your assignment has an extra $
:
export PATH=$PATH:${PWD}:/foo/bar
for a relative answer, use .
test with:
$ myDir=.
$ ls $myDir
$ cd /
$ ls $myDir
The first ls
will show you everything in the current directory, the second will show you everything in the root directory (/
).
current working directory variable ie full path /home/dev/other
dir=$PWD
print the full path
echo $dir
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