source: trunk/essentials/app-shells/bash/tests/printf.tests@ 3506

Last change on this file since 3506 was 3228, checked in by bird, 19 years ago

bash 3.1

File size: 5.6 KB
Line 
1LC_ALL=C
2LC_NUMERIC=C
3
4# these should output error messages -- the format is required
5printf
6printf --
7
8# these should output nothing
9printf ""
10printf -- ""
11
12# in the future this may mean to put the output into VAR, but for
13# now it is an error
14# 2005-03-15 no longer an error
15unset var
16printf -v var "%10d" $RANDOM
17echo ${#var}
18
19# this should expand escape sequences in the format string, nothing else
20printf "\tone\n"
21
22# this should not cut off output after the \c
23printf "one\ctwo\n"
24
25# and unrecognized backslash escapes should have the backslash preserverd
26printf "4\.2\n"
27
28printf "no newline " ; printf "now newline\n"
29
30# %% -> %
31printf "%%\n"
32
33# this was a bug caused by pre-processing the string for backslash escapes
34# before doing the `%' format processing -- all versions before bash-2.04
35printf "\045" ; echo
36printf "\045d\n"
37
38# simple character output
39printf "%c\n" ABCD
40
41# test simple string output
42printf "%s\n" unquoted
43
44# test quoted string output
45printf "%s %q\n" unquoted quoted
46printf "%s%10q\n" unquoted quoted
47
48printf "%q\n" 'this&that'
49
50# make sure the format string is reused to use up arguments
51printf "%d " 1 2 3 4 5; printf "\n"
52
53# make sure that extra format characters get null arguments
54printf "%s %d %d %d\n" onestring
55
56printf "%s %d %u %4.2f\n" onestring
57
58printf -- "--%s %s--\n" 4.2 ''
59printf -- "--%s %s--\n" 4.2
60
61# test %b escapes
62
63# 8 is a non-octal digit, so the `81' should be output
64printf -- "--%b--\n" '\n\081'
65
66printf -- "--%b--\n" '\t\0101'
67printf -- "--%b--\n" '\t\101'
68
69# these should all display `A7'
70echo -e "\1017"
71echo -e "\x417"
72
73printf "%b\n" '\01017'
74printf "%b\n" '\1017'
75printf "%b\n" '\x417'
76
77printf -- "--%b--\n" '\"abcd\"'
78printf -- "--%b--\n" "\'abcd\'"
79