Why I can't change directories using “cd”?

后端 未结 30 2895
眼角桃花
眼角桃花 2020-11-21 06:17

I\'m trying to write a small script to change the current directory to my project directory:

#!/bin/bash
cd /home/tree/projects/java

I save

30条回答
  •  孤城傲影
    2020-11-21 06:26

    It is an old question, but I am really surprised I don't see this trick here

    Instead of using cd you can use

    export PWD=the/path/you/want
    

    No need to create subshells or use aliases.

    Note that it is your responsibility to make sure the/path/you/want exists.

提交回复
热议问题