我想用几个参数使用bash别名和bash函数。我模拟svn子命令。带有几个参数的Bash别名和bash函数
$ svngrep -nr 'Foo' .
$ svn grep -nr 'Foo' .
我的期望是既充当如下:
grep --exclude='*.svn-*' --exclude='entries' -nr 'Foo' .
但实际中,只有别名( 'svngrep')做得很好,功能( 'SVN的grep')导致无效的选项错误。如何写我的.bashrc?
#~/.bashrc
alias svngrep="grep --exclude='*.svn-*' --exclude='entries'"
svn() {
if [[ $1 == grep ]]
then
local remains=$(echo [email protected] | sed -e 's/grep//')
command "$svngrep $remains"
else
command svn "[email protected]"
fi
}
请参阅[BashFAQ/050](http://mywiki.wooledge.org/BashFAQ/050),[Quotes](http://mywiki.wooledge.org/Quotes)和[Special Parameters](http: //mywiki.wooledge.org/BashSheet#Special_Parameters)。 –
这将非常脆弱;请阅读丹尼斯的链接,然后使用@ glenn的解决方案。 –
谢谢,我理解$ *和$ @之间的推论。我必须使用双倍$ @,如“$ @”。 – sanemat