bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

set command overrides my ARGV array


From: Martin MOKREJŠ
Subject: set command overrides my ARGV array
Date: Tue, 27 Dec 2016 17:21:13 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:49.0) Gecko/20100101 Firefox/49.0 SeaMonkey/2.46a1

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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]