[pacman-dev] bash argument passing help
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? Allan
On Tue, Oct 20, 2009 at 9:45 PM, Allan McRae <allan@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@kilkenny /tmp $ ./one.sh -f -h "foo bar" pass 1: -f -h foo bar pass 2: -f -h foo bar dmcgee@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
Dan McGee wrote:
On Tue, Oct 20, 2009 at 9:45 PM, Allan McRae <allan@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@kilkenny /tmp $ ./one.sh -f -h "foo bar" pass 1: -f -h foo bar
pass 2: -f -h foo bar
dmcgee@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
On Tue, Oct 20, 2009 at 10:17 PM, Dan McGee <dpmcgee@gmail.com> wrote:
On Tue, Oct 20, 2009 at 9:45 PM, Allan McRae <allan@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@kilkenny /tmp $ ./one.sh -f -h "foo bar" pass 1: -f -h foo bar
pass 2: -f -h foo bar
dmcgee@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
It's worth noting that the following works two: ./two.sh "$@" The reason being that "$@" is special in bash. It actually expands to the command line quoted as you passed it, with "foo bar" being one argument. The issue is with the assignment to a single bash variable
On Tue, Oct 20, 2009 at 10:28 PM, Aaron Griffin <aaronmgriffin@gmail.com> wrote:
It's worth noting that the following works two: works *too
Damn your scripts being named "one" and "two"
Aaron Griffin wrote:
On Tue, Oct 20, 2009 at 10:17 PM, Dan McGee <dpmcgee@gmail.com> wrote:
On Tue, Oct 20, 2009 at 9:45 PM, Allan McRae <allan@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@kilkenny /tmp $ ./one.sh -f -h "foo bar" pass 1: -f -h foo bar
pass 2: -f -h foo bar
dmcgee@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
It's worth noting that the following works two:
./two.sh "$@"
The reason being that "$@" is special in bash. It actually expands to the command line quoted as you passed it, with "foo bar" being one argument. The issue is with the assignment to a single bash variable
The reason that can not be used in makepkg is the option parsing uses "shift" and thus clears the value of $@ as it goes. Allan
On Tue, Oct 20, 2009 at 10:30 PM, Allan McRae <allan@archlinux.org> wrote:
Aaron Griffin wrote:
On Tue, Oct 20, 2009 at 10:17 PM, Dan McGee <dpmcgee@gmail.com> wrote:
On Tue, Oct 20, 2009 at 9:45 PM, Allan McRae <allan@archlinux.org> wrote:
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.
It's worth noting that the following works two:
./two.sh "$@"
The reason being that "$@" is special in bash. It actually expands to the command line quoted as you passed it, with "foo bar" being one argument. The issue is with the assignment to a single bash variable
The reason that can not be used in makepkg is the option parsing uses "shift" and thus clears the value of $@ as it goes.
I thought I'd craft a witty reply but you beat me with a nicely worded one. I happily trimmed the reply chain above to see the failure to read. :P -Dan
On Tue, Oct 20, 2009 at 10:34 PM, Dan McGee <dpmcgee@gmail.com> wrote:
On Tue, Oct 20, 2009 at 10:30 PM, Allan McRae <allan@archlinux.org> wrote:
Aaron Griffin wrote:
On Tue, Oct 20, 2009 at 10:17 PM, Dan McGee <dpmcgee@gmail.com> wrote:
On Tue, Oct 20, 2009 at 9:45 PM, Allan McRae <allan@archlinux.org> wrote:
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.
It's worth noting that the following works two:
./two.sh "$@"
The reason being that "$@" is special in bash. It actually expands to the command line quoted as you passed it, with "foo bar" being one argument. The issue is with the assignment to a single bash variable
The reason that can not be used in makepkg is the option parsing uses "shift" and thus clears the value of $@ as it goes.
I thought I'd craft a witty reply but you beat me with a nicely worded one. I happily trimmed the reply chain above to see the failure to read. :P
Whoops. I didn't see it mentioned. I did, however, want to point out the fact that "$@" is special. It's not just a variable in quotes. It's crazy like that
participants (3)
-
Aaron Griffin
-
Allan McRae
-
Dan McGee