Path: csiph.com!au2pb.net!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!news.glorb.com!usenet.stanford.edu!not-for-mail From: Linda Walsh Newsgroups: gnu.bash.bug Subject: Re: language inconsistency(wart) & RFE Date: Wed, 21 Oct 2015 19:24:09 -0700 Lines: 103 Approved: bug-bash@gnu.org Message-ID: References: <5621A1DD.90205@tlinx.org> <56226F73.4040908@tlinx.org> <20151019124228.GT27325@eeg.ccf.org> <56281764.1060105@tlinx.org> NNTP-Posting-Host: lists.gnu.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: usenet.stanford.edu 1445480663 3286 208.118.235.17 (22 Oct 2015 02:24:23 GMT) X-Complaints-To: action@cs.stanford.edu Cc: bug-bash Envelope-to: bug-bash@gnu.org User-Agent: Thunderbird In-Reply-To: <56281764.1060105@tlinx.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] X-Received-From: 173.164.175.65 X-BeenThere: bug-bash@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Bug reports for the GNU Bourne Again SHell List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com gnu.bash.bug:11736 Here is an example of what I consider to be strange and/or inconsistent behavior ( tests 2 & 3 fail). test 3's failure is a real puzzler: ----- #!/bin/bash shopt -s expand_aliases ; alias my=declare alias array='my -a' int='my -i' dmp () { printf "%q\n" "${*:?}" ; } ip=10.20.30.40 array parts=() (IFS=.; parts=( $ip ) ) array answers=( '10 20 30 40' '1 .2 .3 .4' '1 222 .3 .4' '192.168.0.1/24::{ [ipaddr]="192.168.0.1/24" [address]="192.168.0.1" [prefixlen]="24" ; }' ) # array addr_fields=(ipaddr address prefixlen) assignparts() { parts=( $ip ) ; } tst0 () { my IFS=. ; assignparts ; echo -E "${parts[@]}"; } tst1 () { my IFS=0 ; assignparts ; echo -E "${parts[@]}"; } tst2 () { parts[1]=222; echo -E "${parts[@]}" ; } tst3 () { my ipaddr="$1"; shift; int status=0 my pat='^([^/]+)/([0-9]+)\s*$' my address prefixlen if [[ ! $ipaddr =~ $pat ]]; then echo >&2 "Error in ip/netsize format: \"$ipaddr\"" status=1 else address=${BASH_REMATCH[1]} prefixlen=${BASH_REMATCH[2]} my out="" for flds in "${addr_fields[@]}"; do out+="[$flds]=\"${!flds}\" " done printf "{ %s; }" "$out" fi return $status } int passno=0 tests=0 my fmt="Case %d got/Expected:\n \"%q\"\n \"%q\"\n" testor () { int tstno my out="" for tstno in {0..3}; do tests+=1 exp="${answers[tstno]}" if [[ $exp =~ :: ]]; then my args="${exp%::*}" exp="${exp#*::}" out="$(tst$tstno $args)" else out="$(tst$tstno)" fi if [[ $out != $exp ]]; then printf >&2 "$fmt" "$tstno" "$out" "$exp" continue fi passno+=1 done } testor echo "Passed $passno/$tests tests." ---------------- output: Case 2 got/Expected: "222" "1\ 222\ .3\ .4" Case 3 got/Expected: "\{\ \[ipaddr\]=\"192.168.0.1/24\"\ \[address\]=\"192.168.0.1\"\ \[prefixlen\]=\"24\"\ \;\ \}" "\{\ \[ipaddr\]=\"192.168.0.1/24\"\ \[address\]=\"192.168.0.1\"\ \[prefixlen\]=\"24\"\ \;\ \}" Passed 2/4 tests. The outputs for case 3 look identical -- I was using %s to print them out, but switched to "%q", to ensure no hidden chars... case 2 -- ??? Why didn't it only change the 1 member?