[pacman-dev] [PATCH] Fix command line argument parsing in makepkg

Sebastian Nowicki sebnow at gmail.com
Wed May 21 16:03:02 EDT 2008


On 22/05/2008, at 1:13 AM, Xavier wrote:

> It is not eval, it is set. As far as I can tell, it is perfectly  
> normal,
> that call seems to be made exactly for that purpose: changing the args
> ($@, $1, etc). And I get the same behavior here anyway.

I see. After some playing around it seems that this version of getopt  
simply doesn't support any parameters. Using "getopt abc $@" works  
fine. When running the test script with "-a -b -c", $@ becomes "-a -b - 
c --". If "getopt -o abs $@" is used, $@ becomes "-- abc -a -b -c", in  
which case makepkg would immediately break out of the loop.

> $ cat test.sh
> #!/bin/bash
> echo "\$@=$@"
> args=$(getopt abc $@)
> if [ $? != 0 ]; then
>    echo "Invalid arguments"
>    exit 1
> fi
> eval set -- $args
> echo "\$@=$@"
> while true; do
>    case "$1" in
>        -a|-b|-c)
>            echo "Got $1"; shift;;
>        *)
>            echo "Invalid: $1"; break;;
>    esac
> done
>
> $ ./test.sh -a -b -c
> $@=-a -b -c
> $@=-a -b -c --
> Got -a
> Got -b
> Got -c
> Invalid: --

After changing "getopt abc $@" to "getopt -o abc $@":
> $ ./test.sh -a -b -c
> $@=-a -b -c
> $@=-- abc -a -b -c
Invalid: --

---
Sebastian Nowicki





More information about the pacman-dev mailing list