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

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

    This should do what you want. Change to the directory of interest (from within the script), and then spawn a new bash shell.

    #!/bin/bash
    
    # saved as mov_dir.sh
    cd ~/mt/v3/rt_linux-rt-tools/
    bash
    

    If you run this, it will take you to the directory of interest and when you exit it it will bring you back to the original place.

    root@intel-corei7-64:~# ./mov_dir.sh
    
    root@intel-corei7-64:~/mt/v3/rt_linux-rt-tools# exit
    root@intel-corei7-64:~#
    

    This will even take you to back to your original directory when you exit (CTRL+d)

提交回复
热议问题