Make a Bash alias that takes a parameter?

后端 未结 20 1958
长发绾君心
长发绾君心 2020-11-21 06:53

I used to use CShell (csh), which lets you make an alias that takes a parameter. The notation was something like

alias junk=\"mv \\\\!* ~/.Trash\"

20条回答
  •  长发绾君心
    2020-11-21 07:23

    All you have to do is make a function inside an alias:

    $ alias mkcd='_mkcd(){ mkdir "$1"; cd "$1";}; _mkcd'
                 ^        *      ^  ^     ^  ^         ^
    

    You must put double quotes around "$1" because single quotes will not work. This is because clashing the quotes at the places marked with arrows confuses the system. Also, a space at the place marked with a star is needed for the function.

提交回复
热议问题