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

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

    You need no script, only set the correct option and create an environment variable.

    shopt -s cdable_vars
    

    in your ~/.bashrc allows to cd to the content of environment variables.

    Create such an environment variable:

    export myjava="/home/tree/projects/java"
    

    and you can use:

    cd myjava
    

    Other alternatives.

提交回复
热议问题