BASH alias $1 $2 ... query
Loïc Grenié
loic.grenie at gmail.com
Sun Apr 19 10:02:54 UTC 2009
2009/4/19 Nils Kassube <kassube at gmx.net>:
> dave selby wrote:
>> I am writing an svn alias that does some stuff before it svn's
>>
>> #!/bin/bash
>>
>> echo -e '\n*** SAFE SVN ***\n'
>>
>> some tidying up ....
>>
>> svn $1 $2 $3 $4 $5 $6 $7 $8 $9
>>
>> It works but '$1 $2 $3 $4 $5 $6 $7 $8 $9' is clumsy and does not
>> always work - is there a neater way
>
> Sure.
>
> svn $@
Sorry, this is svn "$@" *with* quotes.
> However I don't know why your method doesn't always work. There could be
> at least 2 reasons:
>
> a) There may be more than 9 parameters but you only use the first 9.
>
> b) You didn't quote your parameters. If there are spaces in the original
> parameters you would actually call svn with something wrong. Example:
> You originally call your script with
>
> myscript "first parameter" "second parameter"
>
> The script would call svn with 4 parameters instead of 2:
>
> svn "first" "parameter" "second" "parameter"
>
> Therefore it would be better to use
>
> svn "$1" "$2" "$3" "$4" "$5" "$6" "$7" "$8" "$9"
>
> But don't use quoting with $@. If you used
>
> svn "$@"
>
> it would be only one parameter like this:
>
> svn "first parameter second parameter"
No ! It would separate parameters. Instead, svn "$*" would keep
only one parameter. If script is called ssvn, and is called with
arguments: ssvn first "second long" third, then
svn $* would call svn first second long third (4 args)
svn $@ would call call svn first second long third (4 args, same as before)
svn "$*" would call svn "first second long third" (one arg)
svn "$@" would call svn first "second long" third (3 args, as ssvn was called)
Hope this helps,
Loïc
More information about the ubuntu-users
mailing list