mirror of
https://https.git.savannah.gnu.org/git/bash.git
synced 2026-07-16 00:20:49 +02:00
commit bash-20100525 snapshot
This commit is contained in:
+1
-1
@@ -1,4 +1,4 @@
|
||||
BUILD_DIR=/usr/local/build/chet/bash/bash-current
|
||||
BUILD_DIR=/usr/local/build/bash/bash-current
|
||||
THIS_SH=$BUILD_DIR/bash
|
||||
PATH=$PATH:$BUILD_DIR
|
||||
|
||||
|
||||
@@ -55,3 +55,18 @@ here-doc terminated with a parenthesis
|
||||
./comsub-posix1.sub: command substitution: line 2: syntax error near unexpected token `)'
|
||||
./comsub-posix1.sub: command substitution: line 2: ` if x; then echo foo )'
|
||||
after
|
||||
swap32_posix is a function
|
||||
swap32_posix ()
|
||||
{
|
||||
local funcname=swap32_posix;
|
||||
local arg;
|
||||
for arg in "$@";
|
||||
do
|
||||
echo $((
|
||||
($arg & 4278190080) >> 24 |
|
||||
($arg & 16711680) >> 8 |
|
||||
($arg & 65280) << 8 |
|
||||
($arg & 255) << 24
|
||||
));
|
||||
done
|
||||
}
|
||||
|
||||
@@ -198,6 +198,8 @@ eof
|
||||
|
||||
${THIS_SH} ./comsub-posix1.sub
|
||||
|
||||
${THIS_SH} ./comsub-posix2.sub
|
||||
|
||||
# produced a parse error through bash-4.0-beta2
|
||||
: $(echo foo)"
|
||||
"
|
||||
|
||||
@@ -0,0 +1,207 @@
|
||||
|
||||
# works right
|
||||
echo ab$(echo mnop)yz
|
||||
# works right
|
||||
echo ab$(echo mnop
|
||||
)yz
|
||||
#
|
||||
# works right
|
||||
echo $(echo ab
|
||||
)
|
||||
# works right
|
||||
echo $(
|
||||
)
|
||||
echo $()
|
||||
echo ab$()cd
|
||||
|
||||
echo $(case a in (a) echo sh_352.26ax; esac )
|
||||
echo $(case a in (a) echo sh_352.26ay; esac)
|
||||
|
||||
echo $((echo sh_352.25a);(echo sh_352.25b))
|
||||
|
||||
echo $(echo sh_352.27 ')' ")" \)
|
||||
# ) comment
|
||||
)
|
||||
|
||||
echo $(
|
||||
echo abc # a comment with )
|
||||
)
|
||||
|
||||
echo $(
|
||||
cat <<eof
|
||||
here doc with )
|
||||
eof
|
||||
)
|
||||
|
||||
echo $(
|
||||
echo ')'
|
||||
)
|
||||
|
||||
unset x
|
||||
x=$(cat <<"EOF"
|
||||
bad' syntax
|
||||
EOF
|
||||
)
|
||||
echo "$x"
|
||||
unset x
|
||||
|
||||
echo $(for f in \); do echo a; done )
|
||||
echo $(case a in a) echo sh_352.26a; esac )
|
||||
echo $(case a in a) echo sh_352.26a; esac)
|
||||
|
||||
echo $(case a in
|
||||
(a) echo sh_352.26
|
||||
;;
|
||||
esac
|
||||
)
|
||||
|
||||
echo $(case a in
|
||||
a) echo sh_352.26
|
||||
;;
|
||||
esac
|
||||
)
|
||||
|
||||
|
||||
echo $(case a in
|
||||
a) echo sh_352.26
|
||||
;;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
esac
|
||||
|
||||
)
|
||||
|
||||
echo $(( 4<(2+3) ? 1 : 32))
|
||||
|
||||
echo $(cat << end
|
||||
sh_352.28 )
|
||||
end
|
||||
)
|
||||
|
||||
echo $(cat <<- end
|
||||
sh_352.28 )
|
||||
end
|
||||
)
|
||||
|
||||
k=$(case x in x) echo k;; esac)
|
||||
echo $k
|
||||
|
||||
x=$(
|
||||
case $(ls) in
|
||||
example) echo foobix;;
|
||||
esac
|
||||
)
|
||||
|
||||
echo $( echo ab\
|
||||
cd)
|
||||
|
||||
echo `echo ab
|
||||
cd`
|
||||
|
||||
echo `echo ab #xyz
|
||||
cd`
|
||||
|
||||
echo "$(echo abcde)
|
||||
"
|
||||
|
||||
recho "$(echo abcde)
|
||||
"
|
||||
|
||||
echo $(echo abcde)\
|
||||
foo
|
||||
|
||||
recho $(echo abcde)\
|
||||
foo
|
||||
|
||||
recho "wx$(echo abcde)yz"
|
||||
recho "$(echo abcde)"
|
||||
|
||||
echo $(cat <<eof
|
||||
'
|
||||
eof
|
||||
)
|
||||
|
||||
echo after 1
|
||||
|
||||
echo $(cat <<\eof
|
||||
'
|
||||
eof
|
||||
)
|
||||
|
||||
echo after 2
|
||||
|
||||
echo "$(cat <<\eof
|
||||
'
|
||||
eof
|
||||
)"
|
||||
|
||||
echo after 3
|
||||
|
||||
echo "$(cat <<\eof
|
||||
`
|
||||
eof
|
||||
)"
|
||||
|
||||
echo after 4
|
||||
|
||||
echo $(
|
||||
cat << ')'
|
||||
hello
|
||||
)
|
||||
)
|
||||
|
||||
echo after 5
|
||||
|
||||
echo $(cat <<'eof'
|
||||
'
|
||||
eof
|
||||
)
|
||||
|
||||
echo after 6
|
||||
|
||||
echo $(
|
||||
case x in x) echo x;; esac
|
||||
)
|
||||
|
||||
echo $(
|
||||
case x in (x) echo x;; esac
|
||||
)
|
||||
|
||||
echo $(
|
||||
echo 'quoted )'
|
||||
)
|
||||
|
||||
echo $(
|
||||
echo comment # with )
|
||||
)
|
||||
|
||||
echo $(
|
||||
cat <<\eof
|
||||
here-doc with )
|
||||
eof
|
||||
)
|
||||
|
||||
echo $(
|
||||
cat <<\)
|
||||
here-doc terminated with a parenthesis
|
||||
)
|
||||
)
|
||||
|
||||
echo $(
|
||||
cat <<\eof
|
||||
' # or a single back- or doublequote
|
||||
eof
|
||||
)
|
||||
|
||||
${THIS_SH} ./comsub-posix1.sub
|
||||
|
||||
# produced a parse error through bash-4.0-beta2
|
||||
: $(echo foo)"
|
||||
"
|
||||
|
||||
# fixed after bash-4.0 released
|
||||
: $(case a in a) echo ;; # comment
|
||||
esac)
|
||||
@@ -0,0 +1,16 @@
|
||||
# problem with bash-4.x versions before bash-4.2. required posix interp
|
||||
swap32_posix()
|
||||
{
|
||||
local funcname=swap32_posix
|
||||
local arg
|
||||
for arg in "$@"; do
|
||||
echo $((
|
||||
($arg & 4278190080) >> 24 |
|
||||
($arg & 16711680) >> 8 |
|
||||
($arg & 65280) << 8 |
|
||||
($arg & 255) << 24
|
||||
))
|
||||
done
|
||||
}
|
||||
|
||||
type swap32_posix
|
||||
+1
-1
@@ -15,7 +15,7 @@ unset: usage: unset [-f] [-v] [name ...]
|
||||
./errors.tests: line 52: unset: `/bin/sh': not a valid identifier
|
||||
./errors.tests: line 55: unset: cannot simultaneously unset a function and a variable
|
||||
./errors.tests: line 58: declare: -z: invalid option
|
||||
declare: usage: declare [-aAfFilrtux] [-p] [name[=value] ...]
|
||||
declare: usage: declare [-aAfFgilrtux] [-p] [name[=value] ...]
|
||||
./errors.tests: line 60: declare: `-z': not a valid identifier
|
||||
./errors.tests: line 61: declare: `/bin/sh': not a valid identifier
|
||||
./errors.tests: line 65: declare: cannot use `-f' to make functions
|
||||
|
||||
@@ -153,4 +153,17 @@ expect 2 40
|
||||
2 40
|
||||
expect 5 20
|
||||
5 20
|
||||
./func4.sub: line 10: foo: maximum function nesting level exceeded (100)
|
||||
1
|
||||
after: f = 100
|
||||
./func4.sub: line 10: foo: maximum function nesting level exceeded (100)
|
||||
1
|
||||
after: f = 100
|
||||
7
|
||||
after FUNCNEST reset: f = 201
|
||||
7
|
||||
after FUNCNEST unset: f = 201
|
||||
./func4.sub: line 10: foo: maximum function nesting level exceeded (20)
|
||||
1
|
||||
after FUNCNEST assign: f = 38
|
||||
5
|
||||
|
||||
@@ -157,6 +157,9 @@ ${THIS_SH} ./func2.sub
|
||||
# test for some posix-specific function behavior
|
||||
${THIS_SH} ./func3.sub
|
||||
|
||||
# FUNCNEST testing
|
||||
${THIS_SH} ./func4.sub
|
||||
|
||||
unset -f myfunction
|
||||
myfunction() {
|
||||
echo "bad shell function redirection"
|
||||
|
||||
@@ -0,0 +1,176 @@
|
||||
a()
|
||||
{
|
||||
x=$((x - 1))
|
||||
return 5
|
||||
}
|
||||
|
||||
b()
|
||||
{
|
||||
x=$((x - 1))
|
||||
a
|
||||
echo a returns $?
|
||||
return 4
|
||||
}
|
||||
|
||||
c()
|
||||
{
|
||||
x=$((x - 1))
|
||||
b
|
||||
echo b returns $?
|
||||
return 3
|
||||
}
|
||||
|
||||
d()
|
||||
{
|
||||
x=$((x - 1))
|
||||
c
|
||||
echo c returns $?
|
||||
return 2
|
||||
}
|
||||
|
||||
e()
|
||||
{
|
||||
d
|
||||
echo d returns $?
|
||||
echo in e
|
||||
x=$((x - 1))
|
||||
return $x
|
||||
}
|
||||
|
||||
f()
|
||||
{
|
||||
e
|
||||
echo e returned $?
|
||||
echo x is $x
|
||||
return 0
|
||||
}
|
||||
|
||||
x=30
|
||||
f
|
||||
|
||||
# make sure unsetting a local variable preserves the `local' attribute
|
||||
f1()
|
||||
{
|
||||
local zz
|
||||
zz=abcde
|
||||
echo $zz
|
||||
unset zz
|
||||
zz=defghi
|
||||
echo $zz
|
||||
}
|
||||
|
||||
zz=ZZ
|
||||
echo $zz
|
||||
f1
|
||||
echo $zz
|
||||
|
||||
unset -f f1
|
||||
f1()
|
||||
{
|
||||
return 5
|
||||
}
|
||||
|
||||
( f1 )
|
||||
echo $?
|
||||
|
||||
unset -f f1
|
||||
f1()
|
||||
{
|
||||
sleep 5
|
||||
return 5
|
||||
}
|
||||
|
||||
f1 &
|
||||
wait
|
||||
echo $?
|
||||
|
||||
unset -f f1
|
||||
|
||||
f1()
|
||||
{
|
||||
echo $AVAR
|
||||
printenv AVAR
|
||||
}
|
||||
|
||||
AVAR=AVAR
|
||||
echo $AVAR
|
||||
f1
|
||||
AVAR=foo f1
|
||||
echo $AVAR
|
||||
|
||||
unset -f f1
|
||||
# make sure subshells can do a `return' if we're executing in a function
|
||||
f1()
|
||||
{
|
||||
( return 5 )
|
||||
status=$?
|
||||
echo $status
|
||||
return $status
|
||||
}
|
||||
|
||||
f1
|
||||
echo $?
|
||||
|
||||
declare -F f1 # should print just the name
|
||||
declare -f f1 # should print the definition, too
|
||||
|
||||
# no functions should be exported, right?
|
||||
declare -xF
|
||||
declare -xf
|
||||
|
||||
# FUNCNAME tests
|
||||
func2()
|
||||
{
|
||||
echo FUNCNAME = $FUNCNAME
|
||||
}
|
||||
|
||||
func()
|
||||
{
|
||||
echo before: FUNCNAME = $FUNCNAME
|
||||
func2
|
||||
echo after: FUNCNAME = $FUNCNAME
|
||||
}
|
||||
|
||||
echo before: try to assign to FUNCNAME
|
||||
FUNCNAME=7
|
||||
|
||||
echo outside: FUNCNAME = $FUNCNAME
|
||||
func
|
||||
echo outside2: FUNCNAME = $FUNCNAME
|
||||
|
||||
# test exported functions (and cached exportstr)
|
||||
zf()
|
||||
{
|
||||
echo this is zf
|
||||
}
|
||||
export -f zf
|
||||
|
||||
${THIS_SH} -c 'type -t zf'
|
||||
${THIS_SH} -c 'type zf'
|
||||
|
||||
${THIS_SH} ./func1.sub
|
||||
|
||||
# tests for functions whose bodies are not group commands, with and without
|
||||
# attached redirections
|
||||
${THIS_SH} ./func2.sub
|
||||
|
||||
# test for some posix-specific function behavior
|
||||
${THIS_SH} ./func3.sub
|
||||
|
||||
unset -f myfunction
|
||||
myfunction() {
|
||||
echo "bad shell function redirection"
|
||||
} >> /dev/null
|
||||
|
||||
myfunction
|
||||
myfunction | cat
|
||||
|
||||
segv()
|
||||
{
|
||||
echo foo | return 5
|
||||
}
|
||||
|
||||
segv
|
||||
echo $?
|
||||
|
||||
exit 0
|
||||
@@ -0,0 +1,39 @@
|
||||
# test FUNCNEST functionality -- bash-4.2
|
||||
FUNCNEST=100
|
||||
|
||||
foo()
|
||||
{
|
||||
(( f++ ))
|
||||
if (( f > 200 )); then
|
||||
return 7
|
||||
fi
|
||||
foo
|
||||
}
|
||||
|
||||
f=0
|
||||
foo
|
||||
echo $?
|
||||
echo after: f = $f
|
||||
|
||||
f=0
|
||||
foo
|
||||
echo $?
|
||||
echo after: f = $f
|
||||
|
||||
f=0
|
||||
FUNCNEST=0
|
||||
foo
|
||||
echo $?
|
||||
echo after FUNCNEST reset: f = $f
|
||||
|
||||
f=0
|
||||
unset FUNCNEST
|
||||
foo
|
||||
echo $?
|
||||
echo after FUNCNEST unset: f = $f
|
||||
|
||||
FUNCNEST=20
|
||||
f=$(( FUNCNEST - 2 ))
|
||||
foo
|
||||
echo $?
|
||||
echo after FUNCNEST assign: f = $f
|
||||
@@ -0,0 +1,30 @@
|
||||
argv[1] = <foo 'bar' baz>
|
||||
argv[1] = <a b c d>
|
||||
argv[1] = <a b c d>
|
||||
argv[1] = <foo ax{{{}b c d{} bar>
|
||||
argv[2] = <}>
|
||||
argv[3] = <baz>
|
||||
argv[1] = <'foo'>
|
||||
argv[1] = <'foo'>
|
||||
argv[1] = <$a>
|
||||
argv[1] = <'foo'>
|
||||
argv[1] = <foo*bar>
|
||||
argv[1] = <foo*bar>
|
||||
argv[1] = <foo*bar'}>
|
||||
argv[1] = <x'>
|
||||
<.> <x> <.> <> <.> <x> <.>
|
||||
<x> <.> <w> <.> <x> <.> <w> <.>
|
||||
<x> <.> <w> <.> <x> <.> <w> <.>
|
||||
<x> <.> <w> <.> <x> <.> <w> <.>
|
||||
<.> <w> <.> <> <.> <w> <.>
|
||||
<.> <w> <.> <> <.> <w> <.>
|
||||
<x> <.> <x> <.> <x> <.> <x> <.>
|
||||
<x> <.> <w> <.> <x> <.> <w> <.>
|
||||
<x> <.> <w> <.> <x> <.> <w> <.>
|
||||
<x> <.> <w> <.> <x> <.> <w> <.>
|
||||
argv[1] = <'bar>
|
||||
argv[1] = <foo 'bar baz>
|
||||
argv[1] = <z}>
|
||||
argv[1] = <''z}>
|
||||
./posixexp.tests: line 56: unexpected EOF while looking for matching `}'
|
||||
./posixexp.tests: line 59: syntax error: unexpected end of file
|
||||
@@ -0,0 +1,58 @@
|
||||
recho "foo ${IFS+'bar'} baz"
|
||||
recho "a ${IFS+b c} d"
|
||||
|
||||
recho "a ${IFS+"b c"} d"
|
||||
|
||||
u=x
|
||||
recho "foo ${IFS+a$u{{{\}b} c ${IFS+d{}} bar" ${IFS-e{}} baz
|
||||
|
||||
a=foo
|
||||
recho "${IFS+'$a'}"
|
||||
recho "${IFS+"'$a'"}"
|
||||
|
||||
recho ${IFS+'$a'}
|
||||
recho ${IFS+"'$a'"}
|
||||
|
||||
unset a u
|
||||
x='foo*bar'
|
||||
|
||||
recho "${x##"}"}"
|
||||
recho "${x##'}'}"
|
||||
recho "${x##'}"
|
||||
|
||||
recho "${x:-'}'}"
|
||||
|
||||
foo="x'a'y"
|
||||
recho "${foo%*'a'*}"
|
||||
unset x
|
||||
|
||||
unset u
|
||||
v=w
|
||||
printf '<%s> ' ${u+x} . ${v+x} . "${u+x}" . "${v+x}" .; echo
|
||||
printf '<%s> ' ${u-x} . ${v-x} . "${u-x}" . "${v-x}" .; echo
|
||||
printf '<%s> ' ${u=x} . ${v=x} . "${u=x}" . "${v=x}" .; echo
|
||||
printf '<%s> ' ${u?x} . ${v?x} . "${u?x}" . "${v?x}" .; echo
|
||||
printf '<%s> ' ${u#x} . ${v#x} . "${u#x}" . "${v#x}" .; echo
|
||||
printf '<%s> ' ${u%x} . ${v%x} . "${u%x}" . "${v%x}" .; echo
|
||||
printf '<%s> ' ${u:+x} . ${v:+x} . "${u:+x}" . "${v:+x}" .; echo
|
||||
printf '<%s> ' ${u:-x} . ${v:-x} . "${u:-x}" . "${v:-x}" .; echo
|
||||
printf '<%s> ' ${u:=x} . ${v:=x} . "${u:=x}" . "${v:=x}" .; echo
|
||||
printf '<%s> ' ${u:?x} . ${v:?x} . "${u:?x}" . "${v:?x}" .; echo
|
||||
# these are invalid substitution operators
|
||||
#printf '<%s> ' ${u:#x} . ${v:#x} . "${u:#x}" . "${v:#x}" .; echo
|
||||
#printf '<%s> ' ${u:%x} . ${v:%x} . "${u:%x}" . "${v:%x}" .; echo
|
||||
|
||||
unset foo
|
||||
set -o posix
|
||||
|
||||
recho "${IFS+'bar}"
|
||||
recho "foo ${IFS+'bar} baz"
|
||||
|
||||
recho ${IFS+'}'z}
|
||||
recho "${IFS+'}'z}"
|
||||
|
||||
# this will be an error
|
||||
foo=bar
|
||||
echo "${foo:-"a}"
|
||||
|
||||
|
||||
Binary file not shown.
@@ -308,4 +308,9 @@ shopt -s nullglob extglob
|
||||
echo "x$(printf "%b" @(hugo))x"
|
||||
printf -v var "%b" @(hugo); echo "x${var}x"
|
||||
|
||||
# tests variable assignment with -v
|
||||
${THIS_SH} ./printf1.sub
|
||||
|
||||
${THIS_SH} ./printf2.sub
|
||||
|
||||
${THIS_SH} ./printf3.sub
|
||||
|
||||
@@ -0,0 +1,313 @@
|
||||
LC_ALL=C
|
||||
LC_NUMERIC=C
|
||||
|
||||
# these should output error messages -- the format is required
|
||||
printf
|
||||
printf --
|
||||
|
||||
# these should output nothing
|
||||
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"
|
||||
|
||||
# this should not cut off output after the \c
|
||||
printf "one\ctwo\n"
|
||||
|
||||
# and unrecognized backslash escapes should have the backslash preserverd
|
||||
printf "4\.2\n"
|
||||
|
||||
printf "no newline " ; printf "now newline\n"
|
||||
|
||||
# %% -> %
|
||||
printf "%%\n"
|
||||
|
||||
# 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 "\045" ; echo
|
||||
printf "\045d\n"
|
||||
|
||||
# simple character output
|
||||
printf "%c\n" ABCD
|
||||
|
||||
# test simple string output
|
||||
printf "%s\n" unquoted
|
||||
|
||||
# test quoted string output
|
||||
printf "%s %q\n" unquoted quoted
|
||||
printf "%s%10q\n" unquoted quoted
|
||||
|
||||
printf "%q\n" 'this&that'
|
||||
|
||||
# make sure the format string is reused to use up arguments
|
||||
printf "%d " 1 2 3 4 5; printf "\n"
|
||||
|
||||
# make sure that extra format characters get null arguments
|
||||
printf "%s %d %d %d\n" onestring
|
||||
|
||||
printf "%s %d %u %4.2f\n" onestring
|
||||
|
||||
printf -- "--%s %s--\n" 4.2 ''
|
||||
printf -- "--%s %s--\n" 4.2
|
||||
|
||||
# test %b escapes
|
||||
|
||||
# 8 is a non-octal digit, so the `81' should be output
|
||||
printf -- "--%b--\n" '\n\081'
|
||||
|
||||
printf -- "--%b--\n" '\t\0101'
|
||||
printf -- "--%b--\n" '\t\101'
|
||||
|
||||
# these should all display `A7'
|
||||
echo -e "\01017"
|
||||
echo -e "\x417"
|
||||
|
||||
printf "%b\n" '\01017'
|
||||
printf "%b\n" '\1017'
|
||||
printf "%b\n" '\x417'
|
||||
|
||||
printf -- "--%b--\n" '\"abcd\"'
|
||||
printf -- "--%b--\n" "\'abcd\'"
|
||||
|
||||
printf -- "--%b--\n" 'a\\x'
|
||||
|
||||
printf -- "--%b--\n" '\x'
|
||||
|
||||
Z1=$(printf -- "%b\n" '\a\b\e\f\r\v')
|
||||
Z2=$'\a\b\e\f\r\v'
|
||||
|
||||
if [ "$Z1" != "$Z2" ]; then
|
||||
echo "whoops: printf %b and $'' differ" >&2
|
||||
fi
|
||||
unset Z1 Z2
|
||||
|
||||
printf -- "--%b--\n" ''
|
||||
printf -- "--%b--\n"
|
||||
|
||||
# the stuff following the \c should be ignored, as well as the rest
|
||||
# of the format string
|
||||
printf -- "--%b--\n" '4.2\c5.4\n'; printf "\n"
|
||||
|
||||
# unrecognized escape sequences should by displayed unchanged
|
||||
printf -- "--%b--\n" '4\.2'
|
||||
|
||||
# a bare \ should not be processed as an escape sequence
|
||||
printf -- "--%b--\n" '\'
|
||||
|
||||
# make sure extra arguments are ignored if the format string doesn't
|
||||
# actually use them
|
||||
printf "\n" 4.4 BSD
|
||||
printf " " 4.4 BSD ; printf "\n"
|
||||
|
||||
# make sure that a fieldwidth and precision of `*' are handled right
|
||||
printf "%10.8s\n" 4.4BSD
|
||||
printf "%*.*s\n" 10 8 4.4BSD
|
||||
|
||||
printf "%10.8q\n" 4.4BSD
|
||||
printf "%*.*q\n" 10 8 4.4BSD
|
||||
|
||||
printf "%6b\n" 4.4BSD
|
||||
printf "%*b\n" 6 4.4BSD
|
||||
|
||||
# we handle this crap with homemade code in printf.def
|
||||
printf "%10b\n" 4.4BSD
|
||||
printf -- "--%-10b--\n" 4.4BSD
|
||||
printf "%4.2b\n" 4.4BSD
|
||||
printf "%.3b\n" 4.4BSD
|
||||
printf -- "--%-8b--\n" 4.4BSD
|
||||
|
||||
# test numeric conversions -- these four lines should echo identically
|
||||
printf "%d %u %i 0%o 0x%x 0x%X\n" 255 255 255 255 255 255
|
||||
printf "%d %u %i %#o %#x %#X\n" 255 255 255 255 255 255
|
||||
|
||||
printf "%ld %lu %li 0%o 0x%x 0x%X\n" 255 255 255 255 255 255
|
||||
printf "%ld %lu %li %#o %#x %#X\n" 255 255 255 255 255 255
|
||||
|
||||
printf "%10d\n" 42
|
||||
printf "%10d\n" -42
|
||||
|
||||
printf "%*d\n" 10 42
|
||||
printf "%*d\n" 10 -42
|
||||
|
||||
# test some simple floating point formats
|
||||
printf "%4.2f\n" 4.2
|
||||
printf "%#4.2f\n" 4.2
|
||||
printf "%#4.1f\n" 4.2
|
||||
|
||||
printf "%*.*f\n" 4 2 4.2
|
||||
printf "%#*.*f\n" 4 2 4.2
|
||||
printf "%#*.*f\n" 4 1 4.2
|
||||
|
||||
printf "%E\n" 4.2
|
||||
printf "%e\n" 4.2
|
||||
printf "%6.1E\n" 4.2
|
||||
printf "%6.1e\n" 4.2
|
||||
|
||||
printf "%G\n" 4.2
|
||||
printf "%g\n" 4.2
|
||||
printf "%6.2G\n" 4.2
|
||||
printf "%6.2g\n" 4.2
|
||||
|
||||
# test some of the more esoteric features of POSIX.1 printf
|
||||
printf "%d\n" "'string'"
|
||||
printf "%d\n" '"string"'
|
||||
|
||||
printf "%#o\n" "'string'"
|
||||
printf "%#o\n" '"string"'
|
||||
|
||||
printf "%#x\n" "'string'"
|
||||
printf "%#X\n" '"string"'
|
||||
|
||||
printf "%6.2f\n" "'string'"
|
||||
printf "%6.2f\n" '"string"'
|
||||
|
||||
# output from these two lines had better be the same
|
||||
printf -- "--%6.4s--\n" abcdefghijklmnopqrstuvwxyz
|
||||
printf -- "--%6.4b--\n" abcdefghijklmnopqrstuvwxyz
|
||||
|
||||
# and these two also
|
||||
printf -- "--%12.10s--\n" abcdefghijklmnopqrstuvwxyz
|
||||
printf -- "--%12.10b--\n" abcdefghijklmnopqrstuvwxyz
|
||||
|
||||
# tests for translating \' to ' and \\ to \
|
||||
# printf translates \' to ' in the format string...
|
||||
printf "\'abcd\'\n"
|
||||
|
||||
# but not when the %b format specification is used
|
||||
printf "%b\n" \\\'abcd\\\'
|
||||
|
||||
# but both translate \\ to \
|
||||
printf '\\abcd\\\n'
|
||||
printf "%b\n" '\\abcd\\'
|
||||
|
||||
# this was reported as a bug in bash-2.03
|
||||
# these three lines should all echo `26'
|
||||
printf "%d\n" 0x1a
|
||||
printf "%d\n" 032
|
||||
printf "%d\n" 26
|
||||
|
||||
# error messages
|
||||
|
||||
# this should be an overflow, but error messages vary between systems
|
||||
# printf "%lu\n" 4294967296
|
||||
|
||||
# ...but we cannot use this because some systems (SunOS4, for example),
|
||||
# happily ignore overflow conditions in strtol(3)
|
||||
#printf "%ld\n" 4294967296
|
||||
|
||||
printf "%10"
|
||||
printf "ab%Mcd\n"
|
||||
|
||||
# this caused an infinite loop in older versions of printf
|
||||
printf "%y" 0
|
||||
|
||||
# these should print a warning and `0', according to POSIX.2
|
||||
printf "%d\n" GNU
|
||||
printf "%o\n" GNU
|
||||
|
||||
# failures in all bash versions through bash-2.05
|
||||
printf "%.0s" foo
|
||||
printf "%.*s" 0 foo
|
||||
|
||||
printf '%.0b-%.0s\n' foo bar
|
||||
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
|
||||
|
||||
# test cases from an austin-group list discussion
|
||||
# prints ^G as an extension
|
||||
printf '%b\n' '\7'
|
||||
|
||||
# prints ^G
|
||||
printf '%b\n' '\0007'
|
||||
|
||||
# prints NUL then 7
|
||||
printf '\0007\n'
|
||||
|
||||
# prints no more than two hex digits
|
||||
printf '\x07e\n'
|
||||
|
||||
# additional backslash escapes
|
||||
printf '\"\?\n'
|
||||
|
||||
# failures with decimal precisions until after bash-3.1
|
||||
printf '%0.5d\n' 1
|
||||
|
||||
printf '%05d\n' 1
|
||||
printf '%5d\n' 1
|
||||
printf '%0d\n' 1
|
||||
|
||||
# failures with various floating point formats and 0 after bash-3.2
|
||||
|
||||
printf "%G\n" 0
|
||||
printf "%g\n" 0
|
||||
printf "%4.2G\n" 0
|
||||
printf "%4.2g\n" 0
|
||||
|
||||
printf "%G\n" 4
|
||||
printf "%g\n" 4
|
||||
printf "%4.2G\n" 4
|
||||
printf "%4.2g\n" 4
|
||||
|
||||
printf "%F\n" 0
|
||||
printf "%f\n" 0
|
||||
printf "%4.2F\n" 0
|
||||
printf "%4.2f\n" 0
|
||||
|
||||
printf "%F\n" 4
|
||||
printf "%f\n" 4
|
||||
printf "%4.2F\n" 4
|
||||
printf "%4.2f\n" 4
|
||||
|
||||
printf "%E\n" 0
|
||||
printf "%e\n" 0
|
||||
printf "%4.2E\n" 0
|
||||
printf "%4.2e\n" 0
|
||||
|
||||
printf "%E\n" 4
|
||||
printf "%e\n" 4
|
||||
printf "%4.2E\n" 4
|
||||
printf "%4.2e\n" 4
|
||||
|
||||
printf "%08X\n" 2604292517
|
||||
|
||||
# make sure these format specifiers all output '' for empty string arguments
|
||||
echo q
|
||||
printf "%q\n" ""
|
||||
printf "%q\n"
|
||||
|
||||
echo s
|
||||
printf "%s\n" ''
|
||||
printf "%s\n"
|
||||
|
||||
echo b
|
||||
printf "%b\n" ''
|
||||
printf "%b\n"
|
||||
|
||||
# bug in bash versions up to and including bash-3.2
|
||||
v=yyy
|
||||
printf -v var "%s" '/current/working/directory/*.@(m3|i3|ig|mg)'
|
||||
shopt -s nullglob extglob
|
||||
echo "x$(printf "%b" @(hugo))x"
|
||||
printf -v var "%b" @(hugo); echo "x${var}x"
|
||||
|
||||
${THIS_SH} ./printf2.sub
|
||||
|
||||
${THIS_SH} ./printf3.sub
|
||||
+4
-7
@@ -67,8 +67,8 @@ 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" '\n\081'
|
||||
#printf "%s" "$vv"
|
||||
|
||||
printf -v vv -- "--%b--\n" '\t\0101'
|
||||
printf "%s" "$vv"
|
||||
@@ -76,9 +76,6 @@ 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'
|
||||
@@ -326,8 +323,8 @@ printf -v vv '%b\n' '\0007'
|
||||
printf "%s" "$vv"
|
||||
|
||||
# prints NUL then 7
|
||||
printf -v vv '\0007\n'
|
||||
printf "%s" "$vv"
|
||||
#printf -v vv '\0007\n'
|
||||
#printf "%s" "$vv"
|
||||
|
||||
# prints no more than two hex digits
|
||||
printf -v vv '\x07e\n'
|
||||
|
||||
@@ -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"
|
||||
@@ -0,0 +1,53 @@
|
||||
LC_ALL=C
|
||||
LANG=C
|
||||
|
||||
SHELLSTART=$(date +%s)
|
||||
SECS=1275250155
|
||||
export TZ=EST5EDT
|
||||
|
||||
printf "%()T\n" $SECS
|
||||
printf "%(abde)Z\n" -1
|
||||
|
||||
printf "%(%e-%b-%Y %T)T\n" $SECS
|
||||
|
||||
printf -v v1 "%(%e-%b-%Y %T)T\n" $(date +%s)
|
||||
printf -v v2 "%(%e-%b-%Y %T)T\n" -1
|
||||
|
||||
case $v1 in
|
||||
$v2) ;;
|
||||
*) echo "current time and -1 possible mismatch|$v1|$v2|" >&2 ;;
|
||||
esac
|
||||
unset v1 v2
|
||||
|
||||
v1=$(date +%s)
|
||||
printf -v v2 "%(%s)T" -1
|
||||
|
||||
case $v1 in
|
||||
$v2) ;;
|
||||
*) echo "current time mismatch:$v1|$v2|" >&2 ;;
|
||||
esac
|
||||
unset v1 v2
|
||||
|
||||
printf "%(%x %X)T\n" $(( $SECS - 3600 ))
|
||||
|
||||
printf -v v1 "%(%F %r)T\n" $SHELLSTART
|
||||
printf -v v2 "%(%F %r)T\n" -2
|
||||
|
||||
case $v1 in
|
||||
$v2) ;;
|
||||
*) echo "shell start time and -2 possible mismatch|$v1|$v2|" >&2 ;;
|
||||
esac
|
||||
unset v1 v2
|
||||
|
||||
printf "current time: %(%F %r)T\n" $SECS
|
||||
|
||||
printf "epoch time: %(%F %r %z)T\n" 0
|
||||
printf "random time: %(%F %r %z)T\n" $SECS
|
||||
|
||||
printf "local time: %(%+)T\n" $SECS
|
||||
|
||||
# test fieldwidth, justification, precision
|
||||
printf "%-40.50(%+)T date-style time\n" $SECS
|
||||
|
||||
# test fieldwidth, justification, precision, embedded parens
|
||||
printf "%-40.50(%x (foo) %X)T date-style time\n" $SECS
|
||||
@@ -0,0 +1,2 @@
|
||||
${THIS_SH} ./posixexp.tests > /tmp/xx 2>&1
|
||||
diff /tmp/xx posixexp.right && rm -f /tmp/xx
|
||||
@@ -0,0 +1,2 @@
|
||||
${THIS_SH} ./posixexp.tests > /tmp/xx
|
||||
diff /tmp/xx posixexp.right && rm -f /tmp/xx
|
||||
+7
-1
@@ -180,6 +180,12 @@ t -o allexport
|
||||
1
|
||||
t ! -o allexport
|
||||
0
|
||||
t -v unset
|
||||
1
|
||||
t -v set
|
||||
0
|
||||
t -v set
|
||||
0
|
||||
t xx -a yy
|
||||
0
|
||||
t xx -o ""
|
||||
@@ -266,7 +272,7 @@ b ( 1 = 2
|
||||
2
|
||||
./test.tests: line 13: test: too many arguments
|
||||
2
|
||||
./test.tests: line 406: [: missing `]'
|
||||
./test.tests: line 418: [: missing `]'
|
||||
2
|
||||
./test.tests: line 13: test: (: unary operator expected
|
||||
2
|
||||
|
||||
@@ -286,12 +286,24 @@ t -n abcd -a aaa
|
||||
echo 't -n abcd -a -z aaa'
|
||||
t -n abcd -a -z aaa
|
||||
|
||||
# test set or unset shell options
|
||||
set +o allexport
|
||||
echo 't -o allexport'
|
||||
t -o allexport
|
||||
echo 't ! -o allexport'
|
||||
t ! -o allexport
|
||||
|
||||
#test set or unset shell variables
|
||||
unset unset
|
||||
echo 't -v unset'
|
||||
t -v unset
|
||||
set=
|
||||
echo 't -v set'
|
||||
t -v set
|
||||
set=set
|
||||
echo 't -v set'
|
||||
t -v set
|
||||
|
||||
echo 't xx -a yy'
|
||||
t xx -a yy
|
||||
echo 't xx -o ""'
|
||||
|
||||
@@ -0,0 +1,426 @@
|
||||
if (( $UID == 0 )); then
|
||||
echo "test-tests: the test suite should not be run as root" >&2
|
||||
fi
|
||||
|
||||
b()
|
||||
{
|
||||
[ "$@" ]
|
||||
echo $?
|
||||
}
|
||||
|
||||
t()
|
||||
{
|
||||
test "$@"
|
||||
echo $?
|
||||
}
|
||||
|
||||
echo 't -a noexist'
|
||||
t -a noexist
|
||||
echo 't -a run-all'
|
||||
t -a run-all
|
||||
|
||||
echo 't -b run-all'
|
||||
t -b run-all
|
||||
echo 't -b /dev/jb1a'
|
||||
t -b /dev/jb1a
|
||||
|
||||
echo 't -c run-all'
|
||||
t -c run-all
|
||||
echo 't -c /dev/tty'
|
||||
t -c /dev/tty
|
||||
|
||||
echo 't -d run-all'
|
||||
t -d run-all
|
||||
echo 't -d /etc'
|
||||
t -d /etc
|
||||
echo 't -d ""'
|
||||
t -d ""
|
||||
echo 'b -d ""'
|
||||
b -d ""
|
||||
|
||||
echo 't -e noexist'
|
||||
t -e noexist
|
||||
echo 't -e run-all'
|
||||
t -e run-all
|
||||
|
||||
echo 't -f noexist'
|
||||
t -f noexist
|
||||
echo 't -f /dev/tty'
|
||||
t -f /dev/tty
|
||||
echo 't -f run-all'
|
||||
t -f run-all
|
||||
|
||||
echo 't -g run-all'
|
||||
t -g run-all
|
||||
|
||||
touch /tmp/test.setgid
|
||||
chgrp ${GROUPS[0]} /tmp/test.setgid
|
||||
chmod ug+x /tmp/test.setgid
|
||||
chmod g+s /tmp/test.setgid
|
||||
echo 't -g /tmp/test.setgid'
|
||||
t -g /tmp/test.setgid
|
||||
rm -f /tmp/test.setgid
|
||||
|
||||
echo 't -k run-all'
|
||||
t -k run-all
|
||||
|
||||
echo 't -n ""'
|
||||
t -n ""
|
||||
echo 't -n "hello"'
|
||||
t -n "hello"
|
||||
|
||||
echo 't -p run-all'
|
||||
t -p run-all
|
||||
|
||||
echo 't -r noexist'
|
||||
t -r noexist
|
||||
|
||||
if (( $UID != 0 )); then
|
||||
touch /tmp/test.noread
|
||||
chmod a-r /tmp/test.noread
|
||||
echo 't -r /tmp/test.noread'
|
||||
t -r /tmp/test.noread
|
||||
rm -f /tmp/test.noread
|
||||
else
|
||||
echo 't -r /tmp/test.noread'
|
||||
echo 1
|
||||
fi
|
||||
|
||||
echo 't -r run-all'
|
||||
t -r run-all
|
||||
|
||||
echo 't -s noexist'
|
||||
t -s noexist
|
||||
echo 't -s /dev/null'
|
||||
t -s /dev/null
|
||||
echo 't -s run-all'
|
||||
t -s run-all
|
||||
|
||||
echo 't -t 20'
|
||||
t -t 20
|
||||
echo 't -t 0'
|
||||
t -t 0 < /dev/tty
|
||||
|
||||
echo 't -u noexist'
|
||||
t -u noexist
|
||||
|
||||
echo 't -u run-all'
|
||||
t -u run-all
|
||||
|
||||
touch /tmp/test.setuid
|
||||
chmod u+x /tmp/test.setuid # some systems require this to turn on setuid bit
|
||||
chmod u+s /tmp/test.setuid
|
||||
echo 't -u /tmp/test.setuid'
|
||||
t -u /tmp/test.setuid
|
||||
rm -f /tmp/test.setuid
|
||||
|
||||
echo 't -w noexist'
|
||||
t -w noexist
|
||||
|
||||
if (( $UID != 0 )); then
|
||||
touch /tmp/test.nowrite
|
||||
chmod a-w /tmp/test.nowrite
|
||||
echo 't -w /tmp/test.nowrite'
|
||||
t -w /tmp/test.nowrite
|
||||
rm -f /tmp/test.nowrite
|
||||
else
|
||||
echo 't -w /tmp/test.nowrite'
|
||||
echo 1
|
||||
fi
|
||||
|
||||
echo 't -w /dev/null'
|
||||
t -w /dev/null
|
||||
|
||||
echo 't -x noexist'
|
||||
t -x noexist
|
||||
|
||||
touch /tmp/test.exec
|
||||
chmod u+x /tmp/test.exec
|
||||
echo 't -x /tmp/test.exec'
|
||||
t -x /tmp/test.exec
|
||||
rm -f /tmp/test.exec
|
||||
|
||||
touch /tmp/test.noexec
|
||||
chmod u-x /tmp/test.noexec
|
||||
echo 't -x /tmp/test.noexec'
|
||||
t -x /tmp/test.noexec
|
||||
rm -f /tmp/test.noexec
|
||||
|
||||
echo 't -z ""'
|
||||
t -z ""
|
||||
echo 't -z "foo"'
|
||||
t -z "foo"
|
||||
|
||||
echo 't "foo"'
|
||||
t "foo"
|
||||
echo 't ""'
|
||||
t ""
|
||||
|
||||
touch /tmp/test.owner
|
||||
echo 't -O /tmp/test.owner'
|
||||
t -O /tmp/test.owner
|
||||
rm -f /tmp/test.owner
|
||||
|
||||
touch /tmp/test.socket
|
||||
echo 't -S /tmp/test.socket'
|
||||
t -S /tmp/test.socket # false
|
||||
rm -f /tmp/test.socket
|
||||
|
||||
touch /tmp/test.newer
|
||||
echo 't -N /tmp/test.newer'
|
||||
t -N /tmp/test.newer
|
||||
rm -f /tmp/test.newer
|
||||
|
||||
echo 't "hello" = "hello"'
|
||||
t "hello" = "hello"
|
||||
echo 't "hello" = "goodbye"'
|
||||
t "hello" = "goodbye"
|
||||
|
||||
echo 't "hello" == "hello"'
|
||||
t "hello" == "hello"
|
||||
echo 't "hello" == "goodbye"'
|
||||
t "hello" == "goodbye"
|
||||
|
||||
echo 't "hello" != "hello"'
|
||||
t "hello" != "hello"
|
||||
echo 't "hello" != "goodbye"'
|
||||
t "hello" != "goodbye"
|
||||
|
||||
echo 't "hello" < "goodbye"'
|
||||
t "hello" \< "goodbye"
|
||||
echo 't "hello" > "goodbye"'
|
||||
t "hello" \> "goodbye"
|
||||
|
||||
echo 't ! "hello" > "goodbye"'
|
||||
t "! hello" \> "goodbye"
|
||||
|
||||
echo 't 200 -eq 200'
|
||||
t 200 -eq 200
|
||||
echo 't 34 -eq 222'
|
||||
t 34 -eq 222
|
||||
echo 't -32 -eq 32'
|
||||
t -32 -eq 32
|
||||
|
||||
echo 't 200 -ne 200'
|
||||
t 200 -ne 200
|
||||
echo 't 34 -ne 222'
|
||||
t 34 -ne 222
|
||||
|
||||
echo 't 200 -gt 200'
|
||||
t 200 -gt 200
|
||||
echo 't 340 -gt 222'
|
||||
t 340 -gt 222
|
||||
|
||||
echo 't 200 -ge 200'
|
||||
t 200 -ge 200
|
||||
echo 't 34 -ge 222'
|
||||
t 34 -ge 222
|
||||
|
||||
echo 't 200 -lt 200'
|
||||
t 200 -lt 200
|
||||
echo 't 34 -lt 222'
|
||||
t 34 -lt 222
|
||||
|
||||
echo 't 200 -le 200'
|
||||
t 200 -le 200
|
||||
echo 't 340 -le 222'
|
||||
t 340 -le 222
|
||||
|
||||
echo 't 700 -le 1000 -a -n "1" -a "20" = "20"'
|
||||
t 700 -le 1000 -a -n "1" -a "20" = "20"
|
||||
echo 't ! \( 700 -le 1000 -a -n "1" -a "20" = "20" \)'
|
||||
t ! \( 700 -le 1000 -a -n "1" -a "20" = "20" \)
|
||||
|
||||
touch /tmp/abc
|
||||
sleep 2
|
||||
touch /tmp/def
|
||||
|
||||
echo 't /tmp/abc -nt /tmp/def'
|
||||
t /tmp/abc -nt /tmp/def
|
||||
echo 't /tmp/abc -ot /tmp/def'
|
||||
t /tmp/abc -ot /tmp/def
|
||||
echo 't /tmp/def -nt /tmp/abc'
|
||||
t /tmp/def -nt /tmp/abc
|
||||
echo 't /tmp/def -ot /tmp/abc'
|
||||
t /tmp/def -ot /tmp/abc
|
||||
|
||||
echo 't /tmp/abc -ef /tmp/def'
|
||||
t /tmp/abc -ef /tmp/def
|
||||
ln /tmp/abc /tmp/ghi
|
||||
echo 't /tmp/abc -ef /tmp/ghi'
|
||||
t /tmp/abc -ef /tmp/ghi
|
||||
|
||||
rm /tmp/abc /tmp/def /tmp/ghi
|
||||
|
||||
echo 't -r /dev/fd/0'
|
||||
t -r /dev/fd/0
|
||||
echo 't -w /dev/fd/1'
|
||||
t -w /dev/fd/1
|
||||
echo 't -w /dev/fd/2'
|
||||
t -w /dev/fd/2
|
||||
|
||||
echo 't -r /dev/stdin'
|
||||
t -r /dev/stdin
|
||||
echo 't -w /dev/stdout'
|
||||
t -w /dev/stdout
|
||||
echo 't -w /dev/stderr'
|
||||
t -w /dev/stderr
|
||||
|
||||
echo 't'
|
||||
t
|
||||
echo 'b'
|
||||
b
|
||||
|
||||
echo 't 12 -eq 34'
|
||||
t 12 -eq 34
|
||||
echo 't ! 12 -eq 34'
|
||||
t ! 12 -eq 34
|
||||
|
||||
echo 't -n abcd -o aaa'
|
||||
t -n abcd -o aaa
|
||||
echo 't -n abcd -o -z aaa'
|
||||
t -n abcd -o -z aaa
|
||||
|
||||
echo 't -n abcd -a aaa'
|
||||
t -n abcd -a aaa
|
||||
echo 't -n abcd -a -z aaa'
|
||||
t -n abcd -a -z aaa
|
||||
|
||||
set +o allexport
|
||||
echo 't -o allexport'
|
||||
t -o allexport
|
||||
echo 't ! -o allexport'
|
||||
t ! -o allexport
|
||||
|
||||
echo 't xx -a yy'
|
||||
t xx -a yy
|
||||
echo 't xx -o ""'
|
||||
t xx -o ""
|
||||
echo 't xx -a ""'
|
||||
t xx -a ""
|
||||
|
||||
echo 't -X -a -X'
|
||||
t -X -a -X
|
||||
echo 't -X -o -X'
|
||||
t -X -o -X
|
||||
echo 't -X -o ""'
|
||||
t -X -o ""
|
||||
echo 't -X -a ""'
|
||||
t -X -a ""
|
||||
echo 't "" -a -X'
|
||||
t "" -a -X
|
||||
echo 't "" -o -X'
|
||||
t "" -o -X
|
||||
echo 't "" -a ""'
|
||||
t "" -a ""
|
||||
echo 't "" -o ""'
|
||||
t "" -o ""
|
||||
echo 't true -o -X'
|
||||
t true -o -X
|
||||
echo 't true -a -X'
|
||||
t true -a -X
|
||||
|
||||
echo 't ( -E )'
|
||||
t \( -E \)
|
||||
echo 't ( "" )'
|
||||
t \( "" \)
|
||||
|
||||
z=42
|
||||
|
||||
echo 't ! -z "$z"'
|
||||
t ! -z "$z"
|
||||
|
||||
echo 't ! -n "$z"'
|
||||
t ! -n "$z"
|
||||
|
||||
zero=
|
||||
echo 't "$zero"'
|
||||
t "$zero"
|
||||
echo 't ! "$zero"'
|
||||
t ! "$zero"
|
||||
echo 'b "$zero"'
|
||||
b "$zero"
|
||||
echo 'b ! "$zero"'
|
||||
b ! "$zero"
|
||||
|
||||
touch /tmp/test.group
|
||||
chgrp ${GROUPS[0]} /tmp/test.group
|
||||
echo 't -G /tmp/test.group'
|
||||
t -G /tmp/test.group
|
||||
rm /tmp/test.group
|
||||
|
||||
case "${THIS_SH}" in
|
||||
/*) SHNAME=${THIS_SH} ;;
|
||||
*) SHNAME=${PWD}/${THIS_SH} ;;
|
||||
esac
|
||||
|
||||
if ln -s ${SHNAME} /tmp/test.symlink 2>/dev/null; then
|
||||
chgrp ${GROUPS[0]} /tmp/test.symlink 2>/dev/null
|
||||
echo 't -h /tmp/test.symlink'
|
||||
t -h /tmp/test.symlink
|
||||
# some systems don't let you remove this
|
||||
rm -f /tmp/test.symlink 2>/dev/null
|
||||
else
|
||||
echo 't -h /tmp/test.symlink'
|
||||
echo 0
|
||||
fi
|
||||
|
||||
# arithmetic constant errors
|
||||
echo "t 4+3 -eq 7"
|
||||
t 4+3 -eq 7
|
||||
echo "b 4-5 -eq 7"
|
||||
b 4+3 -eq 7
|
||||
|
||||
echo "t 9 -eq 4+5"
|
||||
t 9 -eq 4+5
|
||||
echo "b 9 -eq 4+5"
|
||||
b 9 -eq 4+5
|
||||
|
||||
A=7
|
||||
echo "t A -eq 7"
|
||||
t A -eq 7
|
||||
echo "b A -eq 7"
|
||||
b A -eq 7
|
||||
|
||||
B=9
|
||||
echo "t 9 -eq B"
|
||||
t 9 -eq B
|
||||
echo "b 9 -eq B"
|
||||
b 9 -eq B
|
||||
|
||||
# badly formed expressions
|
||||
echo 't ( 1 = 2'
|
||||
t \( 1 = 2
|
||||
echo 'b ( 1 = 2'
|
||||
b \( 1 = 2
|
||||
|
||||
# more errors
|
||||
t a b
|
||||
t a b c
|
||||
t -A v
|
||||
# too many arguments -- argument expected is also reasonable
|
||||
t 4 -eq 4 -a 2 -ne 5 -a 4 -ne
|
||||
# too many arguments
|
||||
t 4 -eq 4 -a 3 4
|
||||
|
||||
[
|
||||
echo $?
|
||||
|
||||
t \( \)
|
||||
|
||||
# non-numeric arguments to `test -t' should return failure -- fix in 2.05
|
||||
echo 't -t a'
|
||||
t -t a
|
||||
echo 't -t addsds'
|
||||
t -t addsds
|
||||
echo 't -t 42'
|
||||
t -t 42
|
||||
echo 't -t /dev/tty'
|
||||
t -t /dev/tty
|
||||
echo 't -t /dev/tty4'
|
||||
t -t /dev/tty4
|
||||
echo 't -t /dev/tty4444444...'
|
||||
t -t /dev/tty4444444...
|
||||
|
||||
# fixed in bash-4.0-beta
|
||||
t -t ' '
|
||||
Reference in New Issue
Block a user