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

后端 未结 30 3037
眼角桃花
眼角桃花 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:31

    You can do following:

    #!/bin/bash
    cd /your/project/directory
    # start another shell and replacing the current
    exec /bin/bash
    

    EDIT: This could be 'dotted' as well, to prevent creation of subsequent shells.

    Example:

    . ./previous_script  (with or without the first line)
    

提交回复
热议问题