[pacman-dev] bash argument passing help

Allan McRae allan at archlinux.org
Tue Oct 20 23:25:40 EDT 2009


Dan McGee wrote:
> On Tue, Oct 20, 2009 at 9:45 PM, Allan McRae <allan at archlinux.org> wrote:
>   
>> Hi all,
>>
>> This problem has been doing my head in...    First a minimal example that
>> reflects how makepkg does things:
>>
>> --one.sh--
>> #!/bin/bash
>>
>> echo "pass 1:"
>> for arg in "$@"; do
>>  echo $arg
>> done
>> echo
>>
>> ARGLIST="$@"
>>
>> ./two.sh $ARGLIST
>> --end one.sh--
>>
>> --two.sh--
>> #!/bin/bash
>>
>> echo "pass 2:"
>> for arg in "$@"; do
>>  echo $arg
>> done
>> --end two.sh--
>>
>> then run:
>> ./one.sh -f -h "foo bar"
>> pass 1:
>> -f
>> -h
>> foo bar
>>
>> pass 2:
>> -f
>> -h
>> foo
>> bar
>>
>>
>> Note how in pass two, foo and bar are no longer in the one line.   Of
>> course, passing ./two.sh "$@" works, but the argument parsing in makepkg
>> clears that, hence the need to save it to ARGLIST.
>>
>> Any ideas?
>>     
>
> Of course! I think I got it.
>
> dmcgee at kilkenny /tmp
> $ ./one.sh -f -h "foo bar"
> pass 1:
> -f
> -h
> foo bar
>
> pass 2:
> -f
> -h
> foo
> bar
>
> dmcgee at kilkenny /tmp
> $ ./one-new.sh -f -h "foo bar"
> pass 1:
> -f
> -h
> foo bar
>
> pass 2:
> -f
> -h
> foo bar
>
> $ cat one-new.sh
> #!/bin/bash
> echo "pass 1:"
> for arg in "$@"; do
>   echo $arg
> done
> echo
>
> ARGLIST=("$@")
>
> ./two.sh "${ARGLIST[@]}"
>
> Do I win a prize or anything? :P
>
> -Dan
>   

You win makepkg handling rebuilding a list of select package from a 
split PKGBUILD.  Patch on its way.

Also, (far, far less importantly) this allows handling BUILDSCRIPTS with 
space in their name!

Allan



More information about the pacman-dev mailing list