我想用幾個參數使用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