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

后端 未结 30 2422
眼角桃花
眼角桃花 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条回答
  •  Happy的楠姐
    2020-11-21 06:45

    I did the following:

    create a file called case

    paste the following in the file:

    #!/bin/sh
    
    cd /home/"$1"
    

    save it and then:

    chmod +x case
    

    I also created an alias in my .bashrc:

    alias disk='cd /home/; . case'
    

    now when I type:

    case 12345
    

    essentially I am typing:

    cd /home/12345
    

    You can type any folder after 'case':

    case 12
    
    case 15
    
    case 17
    

    which is like typing:

    cd /home/12
    
    cd /home/15
    
    cd /home/17
    

    respectively

    In my case the path is much longer - these guys summed it up with the ~ info earlier.

提交回复
热议问题