Make a Bash alias that takes a parameter?

后端 未结 20 1934
长发绾君心
长发绾君心 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:13

    The question is simply asked wrong. You don't make an alias that takes parameters because alias just adds a second name for something that already exists. The functionality the OP wants is the function command to create a new function. You do not need to alias the function as the function already has a name.

    I think you want something like this :

    function trash() { mv "$@" ~/.Trash; }
    

    That's it! You can use parameters $1, $2, $3, etc, or just stuff them all with $@

提交回复
热议问题