Bash alias and bash function with several arguments
Posted
by
sanemat
on Stack Overflow
See other posts from Stack Overflow
or by sanemat
Published on 2012-06-09T07:33:35Z
Indexed on
2012/06/09
10:40 UTC
Read the original article
Hit count: 946
bash
|bash-alias
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
}
© Stack Overflow or respective owner