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

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

    If you are using fish as your shell, the best solution is to create a function. As an example, given the original question, you could copy the 4 lines below and paste them into your fish command line:

    function proj
       cd /home/tree/projects/java
    end
    funcsave proj
    

    This will create the function and save it for use later. If your project changes, just repeat the process using the new path.

    If you prefer, you can manually add the function file by doing the following:

    nano ~/.config/fish/functions/proj.fish
    

    and enter the text:

    function proj
       cd /home/tree/projects/java
    end
    

    and finally press ctrl+x to exit and y followed by return to save your changes.

    (NOTE: the first method of using funcsave creates the proj.fish file for you).

提交回复
热议问题