set command overrides my ARGV array
Hi, I wanted to enable error code reporting for piped processes. This should be doable by "set -o pipeline on". The problem is it kills my $* array and defines $1="on". $ bash -x /tmp/a.sh arg1 arg2 arg3 + for f in $* + echo arg1 arg1 + for f in $* + echo arg2 arg2 + for f in $* + echo arg3 arg3 + set -o pipefail on + for f in $* + echo on on $ I can work around by storing a $* copy before fiddling with set command. $ cat /tmp/a.sh #! /bin/sh for f in $* ; do echo $f done mybackup=$* set -o pipefail on for f in ${mybackup} ; do echo $f done $ $ bash -x /tmp/a.sh arg1 arg2 arg3 + for f in $* + echo arg1 arg1 + for f in $* + echo arg2 arg2 + for f in $* + echo arg3 arg3 + mybackup='arg1 arg2 arg3' + set -o pipefail on + for f in ${mybackup} + echo arg1 arg1 + for f in ${mybackup} + echo arg2 arg2 + for f in ${mybackup} + echo arg3 arg3 $ I am on Gentoo Linux: # emerge -pv app-shells/bash These are the packages that would be merged, in order: Calculating dependencies... done! [ebuild R] app-shells/bash-4.4_p5-r1::gentoo USE="net nls (readline) -afs -bashlogger -examples -mem-scramble -plugins" 0 KiB Thank you for comments, Martin
Re: set command overrides my ARGV array
On Tue, Dec 27, 2016 at 05:21:13PM +0100, Martin MOKREJ?? wrote: > Hi, > I wanted to enable error code reporting for piped processes. This should > be doable by "set -o pipeline on". There is no such set -o keyword. I think you're looking for "set -o pipefail" instead. (Note: there is no "on". The -o means on. If you use +o it means off.)
Re: set command overrides my ARGV array
On 12/27/2016 10:21 AM, Martin MOKREJŠ wrote: > Hi, > I wanted to enable error code reporting for piped processes. This > should be doable by "set -o pipeline on". The problem is it kills my $* > array and defines $1="on". That's because you used the wrong syntax. 'set -o pipefail' turns it on, 'set +o pipefail' turns it off 'set -o pipefail on' is the same as 'set -o pipefail; set on', which turns it on but also changes $*. -- Eric Blake eblake redhat com+1-919-301-3266 Libvirt virtualization library http://libvirt.org signature.asc Description: OpenPGP digital signature
Re: set command overrides my ARGV array
The syntax is set -o pipefail to turn the option on and set +o pipefail to turn the option off. The word on is not part of the syntax.