What does 'cd -' stand for?

后端 未结 8 1213
星月不相逢
星月不相逢 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.

提交回复
热议问题