Save current directory in variable using Bash?

Solution 1:

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

Solution 2:

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

Solution 3:

Your assignment has an extra $:

export PATH=$PATH:${PWD}:/foo/bar