mirror of
https://https.git.savannah.gnu.org/git/bash.git
synced 2026-07-09 21:20:50 +02:00
commit bash-20050317 snapshot
This commit is contained in:
@@ -39,3 +39,23 @@ argv[1] = <-^?->
|
||||
argv[1] = <^?>
|
||||
argv[1] = <-^?->
|
||||
ok
|
||||
argv[1] = <aaa^?bbb>
|
||||
argv[1] = <ccc^?ddd>
|
||||
argv[1] = <eee^?fff>
|
||||
argv[1] = <ggg^?hhh>
|
||||
argv[1] = <aaabbb>
|
||||
argv[1] = <cccddd>
|
||||
argv[1] = <eeefff>
|
||||
argv[1] = <ggghhh>
|
||||
argv[1] = <aaa^?bbb>
|
||||
argv[1] = <ccc^?ddd>
|
||||
argv[1] = <eee^?fff>
|
||||
argv[1] = <ggg^?hhh>
|
||||
argv[1] = <aaabbb>
|
||||
argv[1] = <cccddd>
|
||||
argv[1] = <eeefff>
|
||||
argv[1] = <ggghhh>
|
||||
argv[1] = <aaa^?bbb>
|
||||
argv[1] = <ccc^?ddd>
|
||||
argv[1] = <eee^?fff>
|
||||
argv[1] = <ggg^?hhh>
|
||||
|
||||
@@ -112,3 +112,32 @@ case "$L1/$L2" in
|
||||
4/4) echo ok;;
|
||||
*) echo CTLNUL bug: L1=$L1, L2=$L2;;
|
||||
esac
|
||||
|
||||
x=$'\177'
|
||||
recho "aaa${x}bbb"
|
||||
recho ccc"${x}"ddd
|
||||
recho eee"$x"fff
|
||||
recho ggg"$(echo $x)"hhh
|
||||
|
||||
x=
|
||||
recho "aaa${x}bbb"
|
||||
recho ccc"${x}"ddd
|
||||
recho eee"$x"fff
|
||||
recho ggg"$(echo $x)"hhh
|
||||
|
||||
set -- $'\177'
|
||||
recho "aaa${1}bbb"
|
||||
recho ccc"${1}"ddd
|
||||
recho eee"$1"fff
|
||||
recho ggg"$(echo $1)"hhh
|
||||
|
||||
set -- ""
|
||||
recho "aaa${1}bbb"
|
||||
recho ccc"${1}"ddd
|
||||
recho eee"$1"fff
|
||||
recho ggg"$(echo $1)"hhh
|
||||
|
||||
recho aaa$'\177'bbb
|
||||
recho ccc""ddd
|
||||
recho "eeefff"
|
||||
recho ggg"$(echo $'\177')"hhh
|
||||
|
||||
@@ -0,0 +1,257 @@
|
||||
# Usage: $SHELL ifs.sh
|
||||
#
|
||||
# This script generates 6856 tests for the set(1) and read(1)
|
||||
# builtins w.r.t. IFS whitespace and non-whitespace characters.
|
||||
# Each failed test produces one line on the standard output that
|
||||
# contains the test along with the expected and actual results.
|
||||
# The last output line contains the test result counts. ordered>0
|
||||
# are the number of tests where IFS=": " produced different results
|
||||
# than IFS=" :". If a test fails the same way for IFS=": " and
|
||||
# IFS=" :" then the second output line is suppressed.
|
||||
|
||||
TESTS=6856
|
||||
|
||||
ksh_read=0
|
||||
echo 1 | read ksh_read
|
||||
ksh_arith=0
|
||||
eval '((ksh_arith+=1))' 2>/dev/null
|
||||
|
||||
failed=0
|
||||
ordered=0
|
||||
passed=0
|
||||
|
||||
split()
|
||||
{
|
||||
i=$1 s=$2 r=$3 S='' R=''
|
||||
for ifs in ': ' ' :'
|
||||
do IFS=$ifs
|
||||
set x $i
|
||||
shift
|
||||
IFS=' '
|
||||
g="[$#]"
|
||||
while :
|
||||
do case $# in
|
||||
0) break ;;
|
||||
esac
|
||||
g="$g($1)"
|
||||
shift
|
||||
done
|
||||
case $g in
|
||||
"$s") case $ksh_arith in
|
||||
1) ((passed+=1)) ;;
|
||||
*) passed=`expr $passed + 1` ;;
|
||||
esac
|
||||
case $S in
|
||||
'') S=$g
|
||||
;;
|
||||
"$g") ;;
|
||||
*) case $ksh_arith in
|
||||
1) ((ordered+=1)) ;;
|
||||
*) ordered=`expr $ordered + 1` ;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
"$S") case $ksh_arith in
|
||||
1) ((failed+=1)) ;;
|
||||
*) failed=`expr $failed + 1` ;;
|
||||
esac
|
||||
;;
|
||||
*) case $ksh_arith in
|
||||
1) ((failed+=1)) ;;
|
||||
*) failed=`expr $failed + 1` ;;
|
||||
esac
|
||||
case $s in
|
||||
"$S") ;;
|
||||
?0*) echo "IFS=\"$ifs\"; x=\"$i\"; set x \$x; shift; echo \"[\$#]\" # expected \"$s\" got \"$g\"" ;;
|
||||
?1*) echo "IFS=\"$ifs\"; x=\"$i\"; set x \$x; shift; echo \"[\$#](\$1)\" # expected \"$s\" got \"$g\"" ;;
|
||||
?2*) echo "IFS=\"$ifs\"; x=\"$i\"; set x \$x; shift; echo \"[\$#](\$1)(\$2)\" # expected \"$s\" got \"$g\"" ;;
|
||||
?3*) echo "IFS=\"$ifs\"; x=\"$i\"; set x \$x; shift; echo \"[\$#](\$1)(\$2)(\$3)\" # expected \"$s\" got \"$g\"" ;;
|
||||
*) echo TEST ERROR i="'$i'" s="'$s'" ;;
|
||||
esac
|
||||
case $S in
|
||||
'') S=$g
|
||||
;;
|
||||
"$g") ;;
|
||||
*) case $ksh_arith in
|
||||
1) ((ordered+=1)) ;;
|
||||
*) ordered=`expr $ordered + 1` ;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
esac
|
||||
case $ksh_read in
|
||||
1) echo "$i" | IFS=$ifs read x y; g="($x)($y)" ;;
|
||||
*) g=`export ifs; echo "$i" | ( IFS=$ifs; read x y; echo "($x)($y)" )` ;;
|
||||
esac
|
||||
case $g in
|
||||
"$r") case $ksh_arith in
|
||||
1) ((passed+=1)) ;;
|
||||
*) passed=`expr $passed + 1` ;;
|
||||
esac
|
||||
case $R in
|
||||
'') R=$g
|
||||
;;
|
||||
"$g") ;;
|
||||
*) case $ksh_arith in
|
||||
1) ((ordered+=1)) ;;
|
||||
*) ordered=`expr $ordered + 1` ;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
"$R") case $ksh_arith in
|
||||
1) ((failed+=1)) ;;
|
||||
*) failed=`expr $failed + 1` ;;
|
||||
esac
|
||||
;;
|
||||
*) case $ksh_arith in
|
||||
1) ((failed+=1)) ;;
|
||||
*) failed=`expr $failed + 1` ;;
|
||||
esac
|
||||
case $r in
|
||||
"$R") ;;
|
||||
*) echo "echo \"$i\" | ( IFS=\"$ifs\" read x y; echo \"(\$x)(\$y)\" ) # expected \"$r\" got \"$g\"" ;;
|
||||
esac
|
||||
case $R in
|
||||
'') R=$g
|
||||
;;
|
||||
"$g") ;;
|
||||
*) case $ksh_arith in
|
||||
1) ((ordered+=1)) ;;
|
||||
*) ordered=`expr $ordered + 1` ;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
for str in \
|
||||
'-' \
|
||||
'a' \
|
||||
'- -' \
|
||||
'- a' \
|
||||
'a -' \
|
||||
'a b' \
|
||||
'- - -' \
|
||||
'- - a' \
|
||||
'- a -' \
|
||||
'- a b' \
|
||||
'a - -' \
|
||||
'a - b' \
|
||||
'a b -' \
|
||||
'a b c' \
|
||||
|
||||
do
|
||||
IFS=' '
|
||||
set x $str
|
||||
|
||||
shift
|
||||
case $# in
|
||||
0) continue ;;
|
||||
esac
|
||||
|
||||
f1=$1
|
||||
case $f1 in
|
||||
'-') f1='' ;;
|
||||
esac
|
||||
|
||||
shift
|
||||
case $# in
|
||||
0) for d0 in '' ' '
|
||||
do
|
||||
for d1 in '' ' ' ':' ' :' ': ' ' : '
|
||||
do
|
||||
case $f1$d1 in
|
||||
'') split "$d0$f1$d1" "[0]" "()()" ;;
|
||||
' ') ;;
|
||||
*) split "$d0$f1$d1" "[1]($f1)" "($f1)()" ;;
|
||||
esac
|
||||
done
|
||||
done
|
||||
continue
|
||||
;;
|
||||
esac
|
||||
f2=$1
|
||||
case $f2 in
|
||||
'-') f2='' ;;
|
||||
esac
|
||||
|
||||
shift
|
||||
case $# in
|
||||
0) for d0 in '' ' '
|
||||
do
|
||||
for d1 in ' ' ':' ' :' ': ' ' : '
|
||||
do
|
||||
case ' ' in
|
||||
$f1$d1|$d1$f2) continue ;;
|
||||
esac
|
||||
for d2 in '' ' ' ':' ' :' ': ' ' : '
|
||||
do
|
||||
case $f2$d2 in
|
||||
'') split "$d0$f1$d1$f2$d2" "[1]($f1)" "($f1)()" ;;
|
||||
' ') ;;
|
||||
*) split "$d0$f1$d1$f2$d2" "[2]($f1)($f2)" "($f1)($f2)" ;;
|
||||
esac
|
||||
done
|
||||
done
|
||||
done
|
||||
continue
|
||||
;;
|
||||
esac
|
||||
f3=$1
|
||||
case $f3 in
|
||||
'-') f3='' ;;
|
||||
esac
|
||||
|
||||
shift
|
||||
case $# in
|
||||
0) for d0 in '' ' '
|
||||
do
|
||||
for d1 in ':' ' :' ': ' ' : '
|
||||
do
|
||||
case ' ' in
|
||||
$f1$d1|$d1$f2) continue ;;
|
||||
esac
|
||||
for d2 in ' ' ':' ' :' ': ' ' : '
|
||||
do
|
||||
case $f2$d2 in
|
||||
' ') continue ;;
|
||||
esac
|
||||
case ' ' in
|
||||
$f2$d2|$d2$f3) continue ;;
|
||||
esac
|
||||
for d3 in '' ' ' ':' ' :' ': ' ' : '
|
||||
do
|
||||
case $f3$d3 in
|
||||
'') split "$d0$f1$d1$f2$d2$f3$d3" "[2]($f1)($f2)" "($f1)($f2)" ;;
|
||||
' ') ;;
|
||||
*) x=$f2$d2$f3$d3
|
||||
x=${x#' '}
|
||||
x=${x%' '}
|
||||
split "$d0$f1$d1$f2$d2$f3$d3" "[3]($f1)($f2)($f3)" "($f1)($x)"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
done
|
||||
done
|
||||
done
|
||||
continue
|
||||
;;
|
||||
esac
|
||||
done
|
||||
case $ksh_arith in
|
||||
1) ((tests=passed+failed)) ;;
|
||||
*) tests=`expr $passed + $failed` ;;
|
||||
esac
|
||||
case $ordered in
|
||||
0) ordered="" ;;
|
||||
*) ordered=" ordered $ordered" ;;
|
||||
esac
|
||||
case $tests in
|
||||
$TESTS) fatal="" ;;
|
||||
*) fatal=" -- fundamental IFS error -- $TESTS tests expected"
|
||||
esac
|
||||
echo "# tests $tests passed $passed failed $failed$ordered$fatal"
|
||||
Binary file not shown.
+12
-4
@@ -9,6 +9,13 @@ printf --
|
||||
printf ""
|
||||
printf -- ""
|
||||
|
||||
# in the future this may mean to put the output into VAR, but for
|
||||
# now it is an error
|
||||
# 2005-03-15 no longer an error
|
||||
unset var
|
||||
printf -v var "%10d" $RANDOM
|
||||
echo ${#var}
|
||||
|
||||
# this should expand escape sequences in the format string, nothing else
|
||||
printf "\tone\n"
|
||||
|
||||
@@ -196,10 +203,6 @@ printf "%d\n" 26
|
||||
# happily ignore overflow conditions in strtol(3)
|
||||
#printf "%ld\n" 4294967296
|
||||
|
||||
# in the future this may mean to put the output into VAR, but for
|
||||
# now it is an error
|
||||
printf -v var "%10d" $RANDOM
|
||||
|
||||
printf "%10"
|
||||
printf "ab%Mcd\n"
|
||||
|
||||
@@ -220,6 +223,11 @@ printf '(%*b)(%*s)\n' -4 foo -4 bar
|
||||
format='%'`printf '%0100384d' 0`'d\n'
|
||||
printf $format 0
|
||||
|
||||
# failures in all bash versions through bash-3.0 - undercounted characters
|
||||
unset vv
|
||||
printf " %s %s %s \n%n" ab cd ef vv
|
||||
echo "$vv"
|
||||
|
||||
# this doesn't work with printf(3) on all systems
|
||||
#printf "%'s\n" foo
|
||||
|
||||
|
||||
@@ -0,0 +1,338 @@
|
||||
LC_ALL=C
|
||||
LC_NUMERIC=C
|
||||
|
||||
unset vv
|
||||
|
||||
# this should expand escape sequences in the format string, nothing else
|
||||
printf -v vv "\tone\n"
|
||||
printf "%s" "$vv"
|
||||
|
||||
# this should not cut off output after the \c
|
||||
printf -v vv "one\ctwo\n"
|
||||
printf "%s" "$vv"
|
||||
|
||||
# and unrecognized backslash escapes should have the backslash preserverd
|
||||
printf -v vv "4\.2\n"
|
||||
printf "%s" "$vv"
|
||||
|
||||
printf -v vv "no newline " ; printf "%s" "$vv" ; printf -v vv "now newline\n"
|
||||
printf "%s" "$vv"
|
||||
|
||||
# %% -> %
|
||||
printf -v vv "%%\n"
|
||||
printf "%s" "$vv"
|
||||
|
||||
# this was a bug caused by pre-processing the string for backslash escapes
|
||||
# before doing the `%' format processing -- all versions before bash-2.04
|
||||
printf -v vv "\045"
|
||||
printf "%s" "$vv"
|
||||
echo
|
||||
printf -v vv "\045d\n"
|
||||
printf "%s" "$vv"
|
||||
|
||||
# simple character output
|
||||
printf -v vv "%c\n" ABCD
|
||||
printf "%s" "$vv"
|
||||
|
||||
# test simple string output
|
||||
printf -v vv "%s\n" unquoted
|
||||
printf "%s" "$vv"
|
||||
|
||||
# test quoted string output
|
||||
printf -v vv "%s %q\n" unquoted quoted
|
||||
printf "%s" "$vv"
|
||||
printf -v vv "%s%10q\n" unquoted quoted
|
||||
printf "%s" "$vv"
|
||||
|
||||
printf -v vv "%q\n" 'this&that'
|
||||
printf "%s" "$vv"
|
||||
|
||||
# make sure the format string is reused to use up arguments
|
||||
printf -v vv "%d " 1 2 3 4 5
|
||||
printf "%s" "$vv"
|
||||
echo
|
||||
|
||||
# make sure that extra format characters get null arguments
|
||||
printf -v vv "%s %d %d %d\n" onestring
|
||||
printf "%s" "$vv"
|
||||
|
||||
printf -v vv "%s %d %u %4.2f\n" onestring
|
||||
printf "%s" "$vv"
|
||||
|
||||
printf -v vv -- "--%s %s--\n" 4.2 ''
|
||||
printf "%s" "$vv"
|
||||
printf -v vv -- "--%s %s--\n" 4.2
|
||||
printf "%s" "$vv"
|
||||
|
||||
# test %b escapes
|
||||
|
||||
# 8 is a non-octal digit, so the `81' should be output
|
||||
printf -v vv -- "--%b--\n" '\n\081'
|
||||
printf "%s" "$vv"
|
||||
|
||||
printf -v vv -- "--%b--\n" '\t\0101'
|
||||
printf "%s" "$vv"
|
||||
printf -v vv -- "--%b--\n" '\t\101'
|
||||
printf "%s" "$vv"
|
||||
|
||||
# these should all display `A7'
|
||||
echo -e "\1017"
|
||||
echo -e "\x417"
|
||||
|
||||
printf -v vv "%b\n" '\01017'
|
||||
printf "%s" "$vv"
|
||||
printf -v vv "%b\n" '\1017'
|
||||
printf "%s" "$vv"
|
||||
printf -v vv "%b\n" '\x417'
|
||||
printf "%s" "$vv"
|
||||
|
||||
printf -v vv -- "--%b--\n" '\"abcd\"'
|
||||
printf "%s" "$vv"
|
||||
printf -v vv -- "--%b--\n" "\'abcd\'"
|
||||
printf "%s" "$vv"
|
||||
|
||||
printf -v vv -- "--%b--\n" 'a\\x'
|
||||
printf "%s" "$vv"
|
||||
|
||||
printf -v vv -- "--%b--\n" '\x'
|
||||
printf "%s" "$vv"
|
||||
|
||||
Z1=$(printf -- "%b\n" '\a\b\e\f\r\v')
|
||||
Z2=$'\a\b\e\f\r\v'
|
||||
|
||||
if [ "$Z1" != "$Z2" ]; then
|
||||
printf "%s" "whoops: printf -v vv %b and $'' differ" >&2
|
||||
fi
|
||||
unset Z1 Z2
|
||||
|
||||
printf -v vv -- "--%b--\n" ''
|
||||
printf "%s" "$vv"
|
||||
printf -v vv -- "--%b--\n"
|
||||
printf "%s" "$vv"
|
||||
|
||||
# the stuff following the \c should be ignored, as well as the rest
|
||||
# of the format string
|
||||
printf -v vv -- "--%b--\n" '4.2\c5.4\n'
|
||||
printf "%s" "$vv"
|
||||
echo
|
||||
|
||||
# unrecognized escape sequences should by displayed unchanged
|
||||
printf -v vv -- "--%b--\n" '4\.2'
|
||||
printf "%s" "$vv"
|
||||
|
||||
# a bare \ should not be processed as an escape sequence
|
||||
printf -v vv -- "--%b--\n" '\'
|
||||
printf "%s" "$vv"
|
||||
|
||||
# make sure extra arguments are ignored if the format string doesn't
|
||||
# actually use them
|
||||
printf -v vv "\n" 4.4 BSD
|
||||
printf "%s" "$vv"
|
||||
printf -v vv " " 4.4 BSD
|
||||
printf "%s" "$vv"
|
||||
echo
|
||||
|
||||
# make sure that a fieldwidth and precision of `*' are handled right
|
||||
printf -v vv "%10.8s\n" 4.4BSD
|
||||
printf "%s" "$vv"
|
||||
printf -v vv "%*.*s\n" 10 8 4.4BSD
|
||||
printf "%s" "$vv"
|
||||
|
||||
printf -v vv "%10.8q\n" 4.4BSD
|
||||
printf "%s" "$vv"
|
||||
printf -v vv "%*.*q\n" 10 8 4.4BSD
|
||||
printf "%s" "$vv"
|
||||
|
||||
printf -v vv "%6b\n" 4.4BSD
|
||||
printf "%s" "$vv"
|
||||
printf -v vv "%*b\n" 6 4.4BSD
|
||||
printf "%s" "$vv"
|
||||
|
||||
# we handle this crap with homemade code in printf -v vv.def
|
||||
printf -v vv "%10b\n" 4.4BSD
|
||||
printf "%s" "$vv"
|
||||
printf -v vv -- "--%-10b--\n" 4.4BSD
|
||||
printf "%s" "$vv"
|
||||
printf -v vv "%4.2b\n" 4.4BSD
|
||||
printf "%s" "$vv"
|
||||
printf -v vv "%.3b\n" 4.4BSD
|
||||
printf "%s" "$vv"
|
||||
printf -v vv -- "--%-8b--\n" 4.4BSD
|
||||
printf "%s" "$vv"
|
||||
|
||||
# test numeric conversions -- these four lines should printf "%s" identically
|
||||
printf -v vv "%d %u %i 0%o 0x%x 0x%X\n" 255 255 255 255 255 255
|
||||
printf "%s" "$vv"
|
||||
printf -v vv "%d %u %i %#o %#x %#X\n" 255 255 255 255 255 255
|
||||
printf "%s" "$vv"
|
||||
|
||||
printf -v vv "%ld %lu %li 0%o 0x%x 0x%X\n" 255 255 255 255 255 255
|
||||
printf "%s" "$vv"
|
||||
printf -v vv "%ld %lu %li %#o %#x %#X\n" 255 255 255 255 255 255
|
||||
printf "%s" "$vv"
|
||||
|
||||
printf -v vv "%10d\n" 42
|
||||
printf "%s" "$vv"
|
||||
printf -v vv "%10d\n" -42
|
||||
printf "%s" "$vv"
|
||||
|
||||
printf -v vv "%*d\n" 10 42
|
||||
printf "%s" "$vv"
|
||||
printf -v vv "%*d\n" 10 -42
|
||||
printf "%s" "$vv"
|
||||
|
||||
# test some simple floating point formats
|
||||
printf -v vv "%4.2f\n" 4.2
|
||||
printf "%s" "$vv"
|
||||
printf -v vv "%#4.2f\n" 4.2
|
||||
printf "%s" "$vv"
|
||||
printf -v vv "%#4.1f\n" 4.2
|
||||
printf "%s" "$vv"
|
||||
|
||||
printf -v vv "%*.*f\n" 4 2 4.2
|
||||
printf "%s" "$vv"
|
||||
printf -v vv "%#*.*f\n" 4 2 4.2
|
||||
printf "%s" "$vv"
|
||||
printf -v vv "%#*.*f\n" 4 1 4.2
|
||||
printf "%s" "$vv"
|
||||
|
||||
printf -v vv "%E\n" 4.2
|
||||
printf "%s" "$vv"
|
||||
printf -v vv "%e\n" 4.2
|
||||
printf "%s" "$vv"
|
||||
printf -v vv "%6.1E\n" 4.2
|
||||
printf "%s" "$vv"
|
||||
printf -v vv "%6.1e\n" 4.2
|
||||
printf "%s" "$vv"
|
||||
|
||||
printf -v vv "%G\n" 4.2
|
||||
printf "%s" "$vv"
|
||||
printf -v vv "%g\n" 4.2
|
||||
printf "%s" "$vv"
|
||||
printf -v vv "%6.2G\n" 4.2
|
||||
printf "%s" "$vv"
|
||||
printf -v vv "%6.2g\n" 4.2
|
||||
printf "%s" "$vv"
|
||||
|
||||
# test some of the more esoteric features of POSIX.1 printf -v vv
|
||||
printf -v vv "%d\n" "'string'"
|
||||
printf "%s" "$vv"
|
||||
printf -v vv "%d\n" '"string"'
|
||||
printf "%s" "$vv"
|
||||
|
||||
printf -v vv "%#o\n" "'string'"
|
||||
printf "%s" "$vv"
|
||||
printf -v vv "%#o\n" '"string"'
|
||||
printf "%s" "$vv"
|
||||
|
||||
printf -v vv "%#x\n" "'string'"
|
||||
printf "%s" "$vv"
|
||||
printf -v vv "%#X\n" '"string"'
|
||||
printf "%s" "$vv"
|
||||
|
||||
printf -v vv "%6.2f\n" "'string'"
|
||||
printf "%s" "$vv"
|
||||
printf -v vv "%6.2f\n" '"string"'
|
||||
printf "%s" "$vv"
|
||||
|
||||
# output from these two lines had better be the same
|
||||
printf -v vv -- "--%6.4s--\n" abcdefghijklmnopqrstuvwxyz
|
||||
printf "%s" "$vv"
|
||||
printf -v vv -- "--%6.4b--\n" abcdefghijklmnopqrstuvwxyz
|
||||
printf "%s" "$vv"
|
||||
|
||||
# and these two also
|
||||
printf -v vv -- "--%12.10s--\n" abcdefghijklmnopqrstuvwxyz
|
||||
printf "%s" "$vv"
|
||||
printf -v vv -- "--%12.10b--\n" abcdefghijklmnopqrstuvwxyz
|
||||
printf "%s" "$vv"
|
||||
|
||||
# tests for translating \' to ' and \\ to \
|
||||
# printf -v vv translates \' to ' in the format string...
|
||||
printf -v vv "\'abcd\'\n"
|
||||
printf "%s" "$vv"
|
||||
|
||||
# but not when the %b format specification is used
|
||||
printf -v vv "%b\n" \\\'abcd\\\'
|
||||
printf "%s" "$vv"
|
||||
|
||||
# but both translate \\ to \
|
||||
printf -v vv '\\abcd\\\n'
|
||||
printf "%s" "$vv"
|
||||
printf -v vv "%b\n" '\\abcd\\'
|
||||
printf "%s" "$vv"
|
||||
|
||||
# this was reported as a bug in bash-2.03
|
||||
# these three lines should all printf "%s" `26'
|
||||
printf -v vv "%d\n" 0x1a
|
||||
printf "%s" "$vv"
|
||||
printf -v vv "%d\n" 032
|
||||
printf "%s" "$vv"
|
||||
printf -v vv "%d\n" 26
|
||||
printf "%s" "$vv"
|
||||
|
||||
# error messages
|
||||
|
||||
# this should be an overflow, but error messages vary between systems
|
||||
# printf -v vv "%lu\n" 4294967296
|
||||
|
||||
# ...but we cannot use this because some systems (SunOS4, for example),
|
||||
# happily ignore overflow conditions in strtol(3)
|
||||
#printf -v vv "%ld\n" 4294967296
|
||||
|
||||
printf -v vv "%10"
|
||||
printf -v vv "ab%Mcd\n"
|
||||
|
||||
# this caused an infinite loop in older versions of printf -v vv
|
||||
printf -v vv "%y" 0
|
||||
|
||||
# these should print a warning and `0', according to POSIX.2
|
||||
printf -v vv "%d\n" GNU
|
||||
printf "%s" "$vv"
|
||||
printf -v vv "%o\n" GNU
|
||||
printf "%s" "$vv"
|
||||
|
||||
# failures in all bash versions through bash-2.05
|
||||
printf -v vv "%.0s" foo
|
||||
printf "%s" "$vv"
|
||||
printf -v vv "%.*s" 0 foo
|
||||
printf "%s" "$vv"
|
||||
|
||||
printf -v vv '%.0b-%.0s\n' foo bar
|
||||
printf "%s" "$vv"
|
||||
printf -v vv '(%*b)(%*s)\n' -4 foo -4 bar
|
||||
printf "%s" "$vv"
|
||||
|
||||
format='%'`printf '%0100384d' 0`'d\n'
|
||||
printf -v vv $format 0
|
||||
printf "%s" "$vv"
|
||||
|
||||
# failures in all bash versions through bash-3.0 - undercounted characters
|
||||
unset vv
|
||||
printf -v vv " %s %s %s \n%n" ab cd ef vvv
|
||||
printf "%s" "$vv"
|
||||
echo $vvv
|
||||
|
||||
# this doesn't work with printf -v vv(3) on all systems
|
||||
#printf -v vv "%'s\n" foo
|
||||
|
||||
# test cases from an austin-group list discussion
|
||||
# prints ^G as an extension
|
||||
printf -v vv '%b\n' '\7'
|
||||
printf "%s" "$vv"
|
||||
|
||||
# prints ^G
|
||||
printf -v vv '%b\n' '\0007'
|
||||
printf "%s" "$vv"
|
||||
|
||||
# prints NUL then 7
|
||||
printf -v vv '\0007\n'
|
||||
printf "%s" "$vv"
|
||||
|
||||
# prints no more than two hex digits
|
||||
printf -v vv '\x07e\n'
|
||||
printf "%s" "$vv"
|
||||
|
||||
# additional backslash escapes
|
||||
printf -v vv '\"\?\n'
|
||||
printf "%s" "$vv"
|
||||
Reference in New Issue
Block a user