Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #11736

Re: language inconsistency(wart) & RFE

Path csiph.com!au2pb.net!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!news.glorb.com!usenet.stanford.edu!not-for-mail
From Linda Walsh <bash@tlinx.org>
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 <mailman.753.1445480663.7904.bug-bash@gnu.org> (permalink)
References <5621A1DD.90205@tlinx.org> <CAAZkfoJzXL_Gc0onFJDnfmHujSTfi=pWte-gsw5k5n24mveKOw@mail.gmail.com> <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 <bug-bash@gnu.org>
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 <bug-bash.gnu.org>
List-Unsubscribe <https://lists.gnu.org/mailman/options/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=unsubscribe>
List-Archive <http://lists.gnu.org/archive/html/bug-bash>
List-Post <mailto:bug-bash@gnu.org>
List-Help <mailto:bug-bash-request@gnu.org?subject=help>
List-Subscribe <https://lists.gnu.org/mailman/listinfo/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=subscribe>
Xref csiph.com gnu.bash.bug:11736

Show key headers only | View raw


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?



Back to gnu.bash.bug | Previous | Next | Find similar


Thread

Re: language inconsistency(wart) & RFE Linda Walsh <bash@tlinx.org> - 2015-10-21 19:24 -0700

csiph-web