NetBSD-Bugs archive

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

bin/57773: /bin/sh: Substring processing in assignments fail for quoted control characters



>Number:         57773
>Category:       bin
>Synopsis:       /bin/sh: Substring processing in assignments fail for quoted control characters
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Dec 14 17:40:00 +0000 2023
>Originator:     Jarle Fredrik Greipsland
>Release:        NetBSD 10.0_BETA
>Organization:
Vennlig hilsen
Jarle Fredrik Greipsland
>Environment:
	
	
System: NetBSD singsaker.uninett.no 10.0_BETA NetBSD 10.0_BETA (GENERIC) #1: Sun Sep 17 11:44:36 CEST 2023  jarle%singsaker.uninett.no@localhost:/usr/obj/sys/arch/amd64/compile/GENERIC amd64
Architecture: x86_64
Machine: amd64
>Description:
If the variable c holds a single character that has a byte value
in the range 129-139, the following parameter expansion with substring
processing produces unexpected results:

  v="X'${c}'"       -> (X'\202')
  v=${v%"'${c}'"}   -> (X'\202') where the expected result is (X)

On the other hand, the same parameter expansion work as expected if it
is not part of an assignment, i.e.
  [ ${v%"'${c}'"} = X ] && echo Expected result.
will print "Expected result."

>How-To-Repeat:
Run the shell snippet below.
--------------------------------------------------
#!/bin/sh

export LC_ALL=C

for n in `jot 255 1`; do
    c=$(printf "$(printf '\\%o' $n)")
    v="X'$c'"
    v=${v%"'$c'"}
    if [ "$v" != X ]; then
	printf "Unexpected result for %d: got (%s), expected (%s)\n" $n "$v" "X"
    fi
done | vis -o

--------------------------------------------------

When run with /bin/sh on NetBSD, all characters outside the range
129-139 produce the expected results.  When run with /bin/ksh and
/usr/pkg/bin/bash, all characters produce the expected results.

	
>Fix:
	

>Unformatted:
 	
 	


Home | Main Index | Thread Index | Old Index