How to make an “alias” for a long path?

前端 未结 10 1942
广开言路
广开言路 2020-12-22 17:58

I tried to make an \"alias\" for a path that I use often while shell scripting. I tried something, but it failed:

myFold=\"~/Files/Scripts/Main\"
cd myFold
         


        
10条回答
  •  醉酒成梦
    2020-12-22 18:15

    First, you need the $ to access "myFold"'s value to make the code in the question work:

    cd "$myFold"
    

    To simplify this you create an alias in ~/.bashrc:

    alias cdmain='cd ~/Files/Scripts/Main'
    

    Don't forget to source the .bashrc once to make the alias become available in the current bash session:

    source ~/.bashrc
    

    Now you can change to the folder using:

    cdmain
    

提交回复
热议问题