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

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

    You can combine an alias and a script,

    alias proj="cd \`/usr/bin/proj !*\`"
    

    provided that the script echos the destination path. Note that those are backticks surrounding the script name. 

    For example, your script could be

    #!/bin/bash
    echo /home/askgelal/projects/java/$1
    

    The advantage with this technique is that the script could take any number of command line parameters and emit different destinations calculated by possibly complex logic.

提交回复
热议问题