Make a Bash alias that takes a parameter?

后端 未结 20 1937
长发绾君心
长发绾君心 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 06:58

    Here's the example:

    alias gcommit='function _f() { git add -A; git commit -m "$1"; } ; _f'
    

    Very important:

    1. There is a space after { and before }.
    2. There is a ; after each command in sequence. If you forget this after the last command, you will see > prompt instead!
    3. The argument is enclosed in quotes as "$1"

提交回复
热议问题