Search code examples
bashvariablesdirectory

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, so that I can run export PATH=$PATH:currentdir+somethingelse. I'm not entirely sure if they have a variable that contains cwd by default.

How do I save the current directory in variable using Bash?


Solution

  • 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