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