What does 'cd -' stand for?

后端 未结 8 1190
星月不相逢
星月不相逢 2020-12-13 05:41

In a bash shell script today I noticed the below command at the end of the script. I know what is cd but I am unaware of the significance of a dash after it.

相关标签:
8条回答
  • 2020-12-13 06:10

    From the manual

    An argument of - is equivalent to $OLDPWD. If a non-empty directory name from CDPATH is used, or if - is the first argument, and the directory change is successful, the absolute pathname of the new working directory is written to the standard output. The return value is true if the directory was successfully changed; false otherwise

    Therefore the - is equivalent to the $OLDPWD, which holds the last directory which the shell was in, and is set by the previous cd invocation.

    0 讨论(0)
  • 2020-12-13 06:13

    cd - returns to the previous directory you were in.

    Say I'm in /usr/ and I type cd /var/local/someplace/else

    Then I use cd - I'll return to /usr

    0 讨论(0)
提交回复
热议问题