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

前端 未结 10 1941
广开言路
广开言路 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:24

    First off, you need to remove the quotes:

    bashboy@host:~$ myFolder=~/Files/Scripts/Main
    

    The quotes prevent the shell from expanding the tilde to its special meaning of being your $HOME directory.

    You could then use $myFolder an environment a shell variable:

    bashboy@host:~$ cd $myFolder
    bashboy@host:~/Files/Scripts/Main$
    

    To make an alias, you need to define the alias:

    alias myfolder="cd $myFolder"
    

    You can then treat this sort of like a command:

    bashboy@host:~$ myFolder
    bashboy@host:~/Files/Scripts/Main$
    

提交回复
热议问题