Bash alias and bash function with several arguments
- by sanemat
I want to use both bash alias and bash function with several arguments. I emulate svn sub commands.
$ svngrep -nr 'Foo' .
$ svn grep -nr 'Foo' .
My expectation is both act as below:
grep --exclude='*.svn-*' --exclude='entries' -nr 'Foo' .
But actual, only alias ('svngrep') does well, function ('svn grep') causes invalid option error. How to write my .bashrc?
#~/.bashrc
alias svngrep="grep --exclude='*.svn-*' --exclude='entries'"
svn() {
if [[ $1 == grep ]]
then
local remains=$(echo $@ | sed -e 's/grep//')
command "$svngrep $remains"
else
command svn "$@"
fi
}