mirror of
https://https.git.savannah.gnu.org/git/bash.git
synced 2026-08-12 05:00:50 +02:00
small change to brace expansion to inhibit some error messages; changes to printf builtin for precision and field widths
This commit is contained in:
@@ -210,6 +210,7 @@ e
|
||||
b c
|
||||
$0
|
||||
declare -a A=([0]="X=a" [1]="b")
|
||||
2 3 4 5 6
|
||||
FIN1:0
|
||||
FIN2:0
|
||||
FIN3:0
|
||||
|
||||
@@ -407,6 +407,10 @@ Z='a b'
|
||||
A=( X=$Z )
|
||||
declare -p A
|
||||
|
||||
# combine with brace expansion
|
||||
letters=( {0..9} )
|
||||
echo "${letters["{2..6}"]}"
|
||||
|
||||
# tests for assigning to noassign array variables
|
||||
BASH_ARGC=(xxx) ; echo FIN1:$?
|
||||
BASH_ARGC=foio ; echo FIN2:$?
|
||||
|
||||
@@ -22,6 +22,11 @@ foobar foobaz
|
||||
bazx bazy
|
||||
vx vy
|
||||
bazx bazy
|
||||
4
|
||||
4
|
||||
./braces.tests: command substitution: line 59: unexpected EOF while looking for matching `)'
|
||||
4
|
||||
4
|
||||
1 2 3 4 5 6 7 8 9 10
|
||||
0..10 braces
|
||||
0 1 2 3 4 5 6 7 8 9 10 braces
|
||||
|
||||
@@ -49,6 +49,17 @@ echo ${var}{x,y}
|
||||
|
||||
unset var varx vary
|
||||
|
||||
# make sure ${ is parsed as a word expansion, since it may contain other
|
||||
# expansions
|
||||
a=4
|
||||
echo "${a#'$('\'}"
|
||||
echo "${a-'$('\'}"
|
||||
echo "${a+'$('\'}"
|
||||
|
||||
echo "${a#aaaa'$(aaaa'aaa)aaa\'}"
|
||||
echo "${a#aaaa'$(aaaa)'aaaa\'}"
|
||||
unset -v a
|
||||
|
||||
# new sequence brace operators
|
||||
echo {1..10}
|
||||
|
||||
|
||||
@@ -166,6 +166,20 @@ argv[2] = <^?>
|
||||
argv[1] = <^A^?>
|
||||
argv[1] = <^A^?^A^?>
|
||||
argv[1] = <^A^A^?>
|
||||
argv[1] = <\^A>
|
||||
argv[1] = <^A>
|
||||
argv[1] = <\^A>
|
||||
argv[1] = <\^A>
|
||||
argv[1] = <^A>
|
||||
argv[1] = <^A>
|
||||
argv[1] = <^A^A>
|
||||
argv[1] = <^A^A>
|
||||
argv[1] = <\^A>
|
||||
argv[1] = <\^A>
|
||||
argv[1] = <\^A^?>
|
||||
argv[1] = <\^A^?>
|
||||
argv[1] = <^\^A ^\^?>
|
||||
argv[1] = <^A ^_>
|
||||
0.net
|
||||
0.net0
|
||||
|
||||
|
||||
@@ -32,3 +32,23 @@ recho $FOO
|
||||
recho ''
|
||||
recho ''
|
||||
recho ''
|
||||
|
||||
# tests of backslash-escaped CTLESC
|
||||
|
||||
recho "${_+\}"
|
||||
recho ${_+\}
|
||||
recho "${_+\\}"
|
||||
recho ${_+\\}
|
||||
recho "${_+}"
|
||||
recho ${_+}
|
||||
recho "${_+}"
|
||||
recho ${_+}
|
||||
|
||||
recho $'\\\1'
|
||||
recho "\\"
|
||||
|
||||
recho "\\"
|
||||
recho \\
|
||||
|
||||
recho $'\c\\\001 \c\\\177'
|
||||
recho $'\c \c'
|
||||
|
||||
+55
-8
@@ -21,6 +21,8 @@ this\&that
|
||||
echo a\\;ls
|
||||
echo a\'\;ls
|
||||
echo 'a'\''b'\;ls
|
||||
\*
|
||||
\*
|
||||
1 2 3 4 5
|
||||
onestring 0 0 0
|
||||
onestring 0 0 0.00
|
||||
@@ -38,7 +40,7 @@ A7
|
||||
--\"abcd\"--
|
||||
--\'abcd\'--
|
||||
--a\x--
|
||||
./printf.tests: line 112: printf: missing hex digit for \x
|
||||
./printf.tests: line 115: printf: missing hex digit for \x
|
||||
--\x--
|
||||
----
|
||||
----
|
||||
@@ -99,12 +101,12 @@ A7
|
||||
26
|
||||
26
|
||||
26
|
||||
./printf.tests: line 236: printf: `%10': missing format character
|
||||
./printf.tests: line 237: printf: `M': invalid format character
|
||||
ab./printf.tests: line 240: printf: `y': invalid format character
|
||||
./printf.tests: line 243: printf: GNU: invalid number
|
||||
./printf.tests: line 239: printf: `%10': missing format character
|
||||
./printf.tests: line 240: printf: `M': invalid format character
|
||||
ab./printf.tests: line 243: printf: `y': invalid format character
|
||||
./printf.tests: line 246: printf: GNU: invalid number
|
||||
0
|
||||
./printf.tests: line 244: printf: GNU: invalid number
|
||||
./printf.tests: line 247: printf: GNU: invalid number
|
||||
0
|
||||
-
|
||||
(foo )(bar )
|
||||
@@ -157,9 +159,15 @@ b
|
||||
xx
|
||||
xx
|
||||
< >< >
|
||||
./printf.tests: line 348: printf: 9223372036854775825: Result too large
|
||||
0
|
||||
^@
|
||||
0
|
||||
0.00
|
||||
''
|
||||
''
|
||||
./printf.tests: line 364: printf: 9223372036854775825: Result too large
|
||||
9223372036854775807
|
||||
./printf.tests: line 349: printf: -9223372036854775815: Result too large
|
||||
./printf.tests: line 365: printf: -9223372036854775815: Result too large
|
||||
-9223372036854775808
|
||||
one
|
||||
one\ctwo
|
||||
@@ -330,6 +338,10 @@ hello --
|
||||
hello --
|
||||
123 --
|
||||
6 --
|
||||
0000000 000
|
||||
0000001
|
||||
0000000 000
|
||||
0000001
|
||||
0000000 340 262 207 340 262 263 340 262 277 340 262 225 340 263 206 340
|
||||
0000010 262 227 340 262 263 340 263 201 012
|
||||
0000019
|
||||
@@ -355,3 +367,38 @@ hello --
|
||||
0000007
|
||||
0000000 340 262 207 040 040 040 055 055 055 012
|
||||
000000a
|
||||
[][]
|
||||
./printf7.sub: line 19: printf: 21474836470: Result too large
|
||||
[]
|
||||
./printf7.sub: line 20: printf: 21474836470: Result too large
|
||||
[X]
|
||||
./printf7.sub: line 22: printf: 21474836470: Result too large
|
||||
VAR=[]
|
||||
./printf7.sub: line 25: printf: 21474836470: Result too large
|
||||
VAR=[X]
|
||||
./printf7.sub: line 31: printf: 9223372036854775825: Result too large
|
||||
[ ]
|
||||
./printf7.sub: line 32: printf: 9223372036854775825: Result too large
|
||||
[X]
|
||||
./printf7.sub: line 34: printf: 9223372036854775825: Result too large
|
||||
VAR=[ ]
|
||||
./printf7.sub: line 37: printf: 9223372036854775825: Result too large
|
||||
VAR=[X]
|
||||
./printf7.sub: line 43: printf: 21474836470: Result too large
|
||||
[]
|
||||
./printf7.sub: line 44: printf: 21474836470: Result too large
|
||||
[X]
|
||||
./printf7.sub: line 46: printf: 21474836470: Result too large
|
||||
VAR=[]
|
||||
./printf7.sub: line 49: printf: 21474836470: Result too large
|
||||
VAR=[X]
|
||||
./printf7.sub: line 55: printf: 9223372036854775825: Result too large
|
||||
[]
|
||||
./printf7.sub: line 56: printf: 9223372036854775825: Result too large
|
||||
[X]
|
||||
./printf7.sub: line 58: printf: 9223372036854775825: Result too large
|
||||
VAR=[]
|
||||
./printf7.sub: line 61: printf: 9223372036854775825: Result too large
|
||||
VAR=[X]
|
||||
XY
|
||||
XY
|
||||
|
||||
+17
-2
@@ -77,6 +77,9 @@ printf 'echo %.2Q%Q\n' "$S" "$T" # note the difference
|
||||
# a different way to do it
|
||||
printf 'echo %.*s%q\n' ${#S1} "$S1" "$T"
|
||||
|
||||
printf '%.1Q\n' '**'
|
||||
printf '%.*Q\n' 1 '**'
|
||||
|
||||
# make sure the format string is reused to use up arguments
|
||||
printf "%d " 1 2 3 4 5; printf "\n"
|
||||
|
||||
@@ -341,6 +344,19 @@ printf -v var "%b" @(hugo); echo "x${var}x"
|
||||
# make sure that missing arguments are always handled like the empty string
|
||||
printf "<%3s><%3b>\n"
|
||||
|
||||
# other format specifiers with missing arguments
|
||||
# 0
|
||||
printf '%d\n'
|
||||
# null char
|
||||
printf '%c\n'
|
||||
|
||||
printf '%x\n'
|
||||
printf '%4.2f\n'
|
||||
|
||||
printf '%b'
|
||||
printf '%q\n'
|
||||
printf '%Q\n'
|
||||
|
||||
# let's test some out-of-range integer errors for POSIX-specified behavior
|
||||
TOOBIG=9223372036854775825
|
||||
TOOSMALL=-9223372036854775815
|
||||
@@ -348,8 +364,6 @@ TOOSMALL=-9223372036854775815
|
||||
printf '%d\n' "$TOOBIG"
|
||||
printf '%d\n' "$TOOSMALL"
|
||||
|
||||
# invalid variable name
|
||||
|
||||
# tests variable assignment with -v
|
||||
${THIS_SH} ./printf1.sub
|
||||
${THIS_SH} ./printf2.sub
|
||||
@@ -358,3 +372,4 @@ ${THIS_SH} ./printf4.sub
|
||||
${THIS_SH} ./printf5.sub
|
||||
# multibyte characters with %ls/%S and %lc/%C
|
||||
${THIS_SH} ./printf6.sub
|
||||
${THIS_SH} ./printf7.sub
|
||||
|
||||
@@ -1,3 +1,24 @@
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
# this should echo nothing
|
||||
printf '%ls'
|
||||
# this should echo a null byte
|
||||
printf '%lc' | hexdump -b
|
||||
|
||||
# this should echo a null byte per posix interp 1647
|
||||
printf '%lc' '' | hexdump -b
|
||||
|
||||
# test %ls and %lc with multibyte characters
|
||||
|
||||
V=ಇಳಿಕೆಗಳು
|
||||
@@ -19,3 +40,6 @@ printf "%C\n" "$V3" | hexdump -b
|
||||
|
||||
printf "%4.2lc\n" "$V3" | hexdump -b
|
||||
printf "%-4.2lc---\n" "$V3" | hexdump -b
|
||||
|
||||
# make sure %ls handles 0 precision the same as %s
|
||||
printf '[%.0s][%.0ls]\n' X X
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
# tests of integer overflow for field width and precision arguments
|
||||
INT_MAX=$(getconf INT_MAX)
|
||||
TOOBIG=$(( $INT_MAX * 10 ))
|
||||
|
||||
printf '[%*s]\n' "${TOOBIG}"
|
||||
printf '[%*s]\n' "${TOOBIG}" X
|
||||
|
||||
printf -v VAR '[%*s]' "${TOOBIG}"
|
||||
echo VAR="$VAR"
|
||||
unset -v VAR
|
||||
printf -v VAR '[%*s]' "${TOOBIG}" X
|
||||
echo VAR="$VAR"
|
||||
unset -v VAR
|
||||
|
||||
TOOBIG=9223372036854775825
|
||||
|
||||
printf '[%*s]\n' "${TOOBIG}"
|
||||
printf '[%*s]\n' "${TOOBIG}" X
|
||||
|
||||
printf -v VAR '[%*s]' "${TOOBIG}"
|
||||
echo VAR="$VAR"
|
||||
unset -v VAR
|
||||
printf -v VAR '[%*s]' "${TOOBIG}" X
|
||||
echo VAR="$VAR"
|
||||
unset -v VAR
|
||||
|
||||
TOOBIG=$(( $INT_MAX * 10 ))
|
||||
|
||||
printf '[%.*s]\n' "${TOOBIG}"
|
||||
printf '[%.*s]\n' "${TOOBIG}" X
|
||||
|
||||
printf -v VAR '[%.*s]' "${TOOBIG}"
|
||||
echo VAR="$VAR"
|
||||
unset -v VAR
|
||||
printf -v VAR '[%.*s]' "${TOOBIG}" X
|
||||
echo VAR="$VAR"
|
||||
unset -v VAR
|
||||
|
||||
TOOBIG=9223372036854775825
|
||||
|
||||
printf '[%.*s]\n' "${TOOBIG}"
|
||||
printf '[%.*s]\n' "${TOOBIG}" X
|
||||
|
||||
printf -v VAR '[%.*s]' "${TOOBIG}"
|
||||
echo VAR="$VAR"
|
||||
unset -v VAR
|
||||
printf -v VAR '[%.*s]' "${TOOBIG}" X
|
||||
echo VAR="$VAR"
|
||||
unset -v VAR
|
||||
|
||||
# out of range inline precisions
|
||||
|
||||
printf "%.${TOOBIG}s\n" XY
|
||||
printf "%.${TOOBIG}Q\n" XY
|
||||
@@ -31,6 +31,8 @@ argv[1] = < foo>
|
||||
argv[1] = <foo>
|
||||
argv[1] = <foo>
|
||||
argv[1] = < foo>
|
||||
./read.tests: line 101: b: readonly variable
|
||||
a = a b = c = stat = 2
|
||||
a = abcdefg
|
||||
xyz
|
||||
a = xyz
|
||||
|
||||
@@ -96,6 +96,15 @@ echo " foo" | { IFS=$' \t\n' ; read line; recho "$line"; }
|
||||
|
||||
echo " foo" | { IFS=$':' ; read line; recho "$line"; }
|
||||
|
||||
# this leaves `b' readonly
|
||||
readonly b
|
||||
read a b c <<EOF
|
||||
a b c
|
||||
EOF
|
||||
|
||||
# the latest POSIX draft says $? should be > 1
|
||||
echo a = $a b = $b c = $c stat = $?
|
||||
|
||||
# test read -d delim behavior
|
||||
${THIS_SH} ./read1.sub
|
||||
|
||||
|
||||
+1
-1
@@ -1,2 +1,2 @@
|
||||
${THIS_SH} ./braces.tests > ${BASH_TSTOUT}
|
||||
${THIS_SH} ./braces.tests > ${BASH_TSTOUT} 2>&1
|
||||
diff ${BASH_TSTOUT} braces.right && rm -f ${BASH_TSTOUT}
|
||||
|
||||
Reference in New Issue
Block a user