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

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

    You're doing nothing wrong! You've changed the directory, but only within the subshell that runs the script.

    You can run the script in your current process with the "dot" command:

    . proj
    

    But I'd prefer Greg's suggestion to use an alias in this simple case.

提交回复
热议问题