2013-03-03 03:15:34 +08:00
|
|
|
printf "Hello %d %i %f %F %g %G\n" 1 2 3 4 5 6
|
|
|
|
|
2013-04-04 09:04:17 +08:00
|
|
|
printf "%x %X %o %llu\n" 10 11 8 -1
|
2014-11-02 15:27:52 +08:00
|
|
|
# %a has OS-dependent output - see #1139
|
|
|
|
#printf "%a %A\n" 14 15
|
2013-03-03 03:15:34 +08:00
|
|
|
|
|
|
|
printf "%c %s\n" a hello
|
2014-09-22 14:19:57 +08:00
|
|
|
printf "%c%c%c\n" hello … o
|
2013-03-03 03:15:34 +08:00
|
|
|
printf "%e %E\n" 5 6
|
|
|
|
|
|
|
|
printf "%20d\n" 50
|
|
|
|
printf "%-20d%d\n" 5 10
|
|
|
|
|
|
|
|
printf "%*d\n" 10 100
|
|
|
|
|
2016-09-06 10:28:41 +08:00
|
|
|
printf "%%\"\\\n"
|
2013-03-03 03:15:34 +08:00
|
|
|
printf "%s\b%s\n" x y
|
|
|
|
printf "abc\rdef\n"
|
|
|
|
printf "Msg1\fMsg2\n"
|
|
|
|
printf "foo\vbar\vbaz\n"
|
2013-03-29 14:56:15 +08:00
|
|
|
printf "\111 \x50 \u0051 \U00000052"
|
2013-03-25 06:24:29 +08:00
|
|
|
|
|
|
|
echo
|
|
|
|
echo "Test escapes"
|
|
|
|
|
|
|
|
# \c escape means "stop printing"
|
|
|
|
printf 'a\cb'
|
|
|
|
echo
|
|
|
|
|
|
|
|
# Bogus printf specifier, should produce no stdout
|
2018-04-02 04:43:05 +08:00
|
|
|
printf "%5" 10 2>/dev/null
|
2013-03-25 06:24:29 +08:00
|
|
|
|
2015-01-16 03:21:07 +08:00
|
|
|
# Octal escapes produce literal bytes, not characters
|
|
|
|
# \376 is 0xFE
|
2017-02-01 10:44:02 +08:00
|
|
|
printf '\376' | display_bytes
|
2015-01-16 03:21:07 +08:00
|
|
|
|
2016-08-30 11:11:40 +08:00
|
|
|
# Verify that floating point conversions and output work correctly with
|
|
|
|
# different combinations of locales and floating point strings. See issue
|
|
|
|
# #3334. This starts by assuming an locale using english conventions.
|
|
|
|
printf '%e\n' "1.23" # should succeed, output should be 1.230000e+00
|
|
|
|
printf '%e\n' "2,34" # should fail
|
2016-09-06 10:28:41 +08:00
|
|
|
|
|
|
|
# Try to use one of several locales that use a comma as the decimal mark
|
|
|
|
# rather than the period used in english speaking locales. If we don't find
|
|
|
|
# one installed we simply don't run this test.
|
2018-12-17 03:30:39 +08:00
|
|
|
#
|
|
|
|
# musl currently does not have a `locale` command, so we also skip it then.
|
|
|
|
set -l locales (command -sq locale; and locale -a)
|
2016-09-06 10:28:41 +08:00
|
|
|
set -l acceptable_locales bg_BG de_DE es_ES fr_FR ru_RU
|
|
|
|
set -l numeric_locale
|
|
|
|
for locale in {$acceptable_locales}.{UTF-8,UTF8}
|
|
|
|
if string match -i -q $locale $locales
|
|
|
|
set numeric_locale $locale
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if set -q numeric_locale[1]
|
|
|
|
set -x LC_NUMERIC $numeric_locale
|
|
|
|
printf '%e\n' "3,45" # should succeed, output should be 3,450000e+00
|
|
|
|
printf '%e\n' "4.56" # should succeed, output should be 4,560000e+00
|
|
|
|
else
|
|
|
|
echo '3,450000e+00'
|
|
|
|
echo '4,560000e+00'
|
|
|
|
end
|
2017-02-21 09:58:08 +08:00
|
|
|
|
|
|
|
# Verify long long ints are handled correctly. See issue #3352.
|
|
|
|
printf 'long hex1 %x\n' 498216206234
|
|
|
|
printf 'long hex2 %X\n' 498216206234
|
|
|
|
printf 'long hex3 %X\n' 0xABCDEF1234567890
|
|
|
|
printf 'long hex4 %X\n' 0xABCDEF12345678901
|
|
|
|
printf 'long decimal %d\n' 498216206594
|
|
|
|
printf 'long signed %d\n' -498216206595
|
|
|
|
printf 'long signed to unsigned %u\n' -498216206596
|
2019-03-17 23:33:58 +08:00
|
|
|
|
|
|
|
# Verify numeric conversion still happens even if it couldn't be fully converted
|
|
|
|
printf '%d\n' 15.1
|
|
|
|
echo $status
|