2019-06-10 02:13:31 +08:00
|
|
|
|
# RUN: %fish %s
|
|
|
|
|
|
2022-11-01 10:50:17 +08:00
|
|
|
|
printf "%d %d\n" 1 2 3
|
|
|
|
|
# CHECK: 1 2
|
|
|
|
|
# CHECK: 3 0
|
|
|
|
|
|
2013-03-03 03:15:34 +08:00
|
|
|
|
printf "Hello %d %i %f %F %g %G\n" 1 2 3 4 5 6
|
2019-06-10 02:13:31 +08:00
|
|
|
|
# CHECK: Hello 1 2 3.000000 4.000000 5 6
|
2013-03-03 03:15:34 +08:00
|
|
|
|
|
2013-04-04 09:04:17 +08:00
|
|
|
|
printf "%x %X %o %llu\n" 10 11 8 -1
|
2019-06-10 02:13:31 +08:00
|
|
|
|
# CHECK: a B 10 18446744073709551615
|
|
|
|
|
|
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
|
2019-06-10 02:13:31 +08:00
|
|
|
|
# CHECK: a hello
|
|
|
|
|
|
2014-09-22 14:19:57 +08:00
|
|
|
|
printf "%c%c%c\n" hello … o
|
2019-06-10 02:13:31 +08:00
|
|
|
|
# CHECK: h…o
|
|
|
|
|
|
2013-03-03 03:15:34 +08:00
|
|
|
|
printf "%e %E\n" 5 6
|
2019-06-10 02:13:31 +08:00
|
|
|
|
# CHECK: 5.000000e+00 6.000000E+00
|
2013-03-03 03:15:34 +08:00
|
|
|
|
|
|
|
|
|
printf "%20d\n" 50
|
2019-06-10 02:13:31 +08:00
|
|
|
|
# CHECK: 50
|
|
|
|
|
|
2013-03-03 03:15:34 +08:00
|
|
|
|
printf "%-20d%d\n" 5 10
|
2019-06-10 02:13:31 +08:00
|
|
|
|
# CHECK: 5 10
|
2013-03-03 03:15:34 +08:00
|
|
|
|
|
|
|
|
|
printf "%*d\n" 10 100
|
2019-06-10 02:13:31 +08:00
|
|
|
|
# CHECK: 100
|
2013-03-03 03:15:34 +08:00
|
|
|
|
|
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
|
2019-06-10 02:13:31 +08:00
|
|
|
|
# CHECK: %"\nxy
|
|
|
|
|
|
2013-03-03 03:15:34 +08:00
|
|
|
|
printf "abc\rdef\n"
|
2019-06-10 02:13:31 +08:00
|
|
|
|
# CHECK: abc{{\r}}def
|
|
|
|
|
|
2013-03-03 03:15:34 +08:00
|
|
|
|
printf "Msg1\fMsg2\n"
|
2019-06-10 02:13:31 +08:00
|
|
|
|
# CHECK: Msg1{{\f}}Msg2
|
|
|
|
|
|
2013-03-03 03:15:34 +08:00
|
|
|
|
printf "foo\vbar\vbaz\n"
|
2019-06-10 02:13:31 +08:00
|
|
|
|
# CHECK: foobarbaz
|
2013-03-25 06:24:29 +08:00
|
|
|
|
|
2019-06-10 02:13:31 +08:00
|
|
|
|
printf "\111 \x50 \u0051 \U00000052"
|
2013-03-25 06:24:29 +08:00
|
|
|
|
echo
|
2019-06-10 02:13:31 +08:00
|
|
|
|
# CHECK: I P Q R
|
2013-03-25 06:24:29 +08:00
|
|
|
|
|
|
|
|
|
# \c escape means "stop printing"
|
|
|
|
|
printf 'a\cb'
|
|
|
|
|
echo
|
2019-06-10 02:13:31 +08:00
|
|
|
|
# CHECK: a
|
2013-03-25 06:24:29 +08:00
|
|
|
|
|
|
|
|
|
# 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
|
2019-06-10 02:13:31 +08:00
|
|
|
|
# CHECK: 0000000 376
|
|
|
|
|
# CHECK: 0000001
|
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.
|
2020-01-14 03:34:22 +08:00
|
|
|
|
printf '%e\n' "1.23" # should succeed, output should be 1.230000e+00
|
2019-06-10 02:13:31 +08:00
|
|
|
|
# CHECK: 1.230000e+00
|
|
|
|
|
|
2020-01-14 03:34:22 +08:00
|
|
|
|
printf '%e\n' "2,34" # should fail
|
2019-06-10 02:13:31 +08:00
|
|
|
|
# CHECK: 2.000000e+00
|
2021-11-20 04:19:56 +08:00
|
|
|
|
# CHECKERR: 2,34: value not completely converted (can't convert ',34')
|
2016-09-06 10:28:41 +08:00
|
|
|
|
|
2017-02-21 09:58:08 +08:00
|
|
|
|
# Verify long long ints are handled correctly. See issue #3352.
|
|
|
|
|
printf 'long hex1 %x\n' 498216206234
|
2019-06-10 02:13:31 +08:00
|
|
|
|
# CHECK: long hex1 73ffffff9a
|
2017-02-21 09:58:08 +08:00
|
|
|
|
printf 'long hex2 %X\n' 498216206234
|
2019-06-10 02:13:31 +08:00
|
|
|
|
# CHECK: long hex2 73FFFFFF9A
|
2017-02-21 09:58:08 +08:00
|
|
|
|
printf 'long hex3 %X\n' 0xABCDEF1234567890
|
2019-06-10 02:13:31 +08:00
|
|
|
|
# CHECK: long hex3 ABCDEF1234567890
|
2017-02-21 09:58:08 +08:00
|
|
|
|
printf 'long hex4 %X\n' 0xABCDEF12345678901
|
2019-06-10 02:13:31 +08:00
|
|
|
|
# CHECKERR: 0xABCDEF12345678901: Number out of range
|
2017-02-21 09:58:08 +08:00
|
|
|
|
printf 'long decimal %d\n' 498216206594
|
2019-06-10 02:13:31 +08:00
|
|
|
|
# CHECK: long hex4 long decimal 498216206594
|
2017-02-21 09:58:08 +08:00
|
|
|
|
printf 'long signed %d\n' -498216206595
|
2019-06-10 02:13:31 +08:00
|
|
|
|
# CHECK: long signed -498216206595
|
2017-02-21 09:58:08 +08:00
|
|
|
|
printf 'long signed to unsigned %u\n' -498216206596
|
2019-06-10 02:13:31 +08:00
|
|
|
|
# CHECK: long signed to unsigned 18446743575493345020
|
2019-03-17 23:33:58 +08:00
|
|
|
|
|
2020-05-19 01:34:53 +08:00
|
|
|
|
# Just check that we print no error for no arguments
|
|
|
|
|
printf
|
|
|
|
|
echo $status
|
|
|
|
|
# CHECK: 2
|
|
|
|
|
|
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
|
2019-06-10 02:13:31 +08:00
|
|
|
|
# CHECK: 15
|
2021-11-20 04:19:56 +08:00
|
|
|
|
# CHECKERR: 15.1: value not completely converted (can't convert '.1')
|
2019-03-17 23:33:58 +08:00
|
|
|
|
echo $status
|
2019-06-10 02:13:31 +08:00
|
|
|
|
# CHECK: 1
|
2022-06-24 00:12:13 +08:00
|
|
|
|
|
|
|
|
|
printf '%d\n' 07
|
|
|
|
|
# CHECK: 7
|
|
|
|
|
echo $status
|
|
|
|
|
# CHECK: 0
|
|
|
|
|
printf '%d\n' 08
|
|
|
|
|
# CHECK: 0
|
|
|
|
|
# CHECKERR: 08: value not completely converted (can't convert '8')
|
|
|
|
|
# CHECKERR: Hint: a leading '0' without an 'x' indicates an octal number
|
|
|
|
|
echo $status
|
|
|
|
|
# CHECK: 1
|
|
|
|
|
|
|
|
|
|
printf '%d\n' 0f
|
|
|
|
|
# CHECK: 0
|
|
|
|
|
# CHECKERR: 0f: value not completely converted (can't convert 'f')
|
|
|
|
|
# CHECKERR: Hint: a leading '0' without an 'x' indicates an octal number
|
|
|
|
|
echo $status
|
|
|
|
|
# CHECK: 1
|
|
|
|
|
|
|
|
|
|
printf '%d\n' 0g
|
|
|
|
|
# CHECK: 0
|
|
|
|
|
# CHECKERR: 0g: value not completely converted (can't convert 'g')
|
|
|
|
|
echo $status
|
|
|
|
|
# CHECK: 1
|
2022-08-10 22:55:56 +08:00
|
|
|
|
|
2023-04-02 01:17:49 +08:00
|
|
|
|
printf '%f\n' 0x2
|
|
|
|
|
# CHECK: 2.000000
|
|
|
|
|
|
|
|
|
|
printf '%f\n' 0x2p3
|
|
|
|
|
# CHECK: 16.000000
|
|
|
|
|
|
|
|
|
|
printf '%.1f\n' -0X1.5P8
|
|
|
|
|
# CHECK: -336.0
|
|
|
|
|
|
2022-08-10 22:55:56 +08:00
|
|
|
|
# Test that we ignore options
|
|
|
|
|
printf -a
|
|
|
|
|
printf --foo
|
|
|
|
|
# CHECK: -a--foo
|
|
|
|
|
echo
|
|
|
|
|
|
|
|
|
|
set -l helpvar --help
|
|
|
|
|
printf $helpvar
|
|
|
|
|
echo
|
|
|
|
|
# CHECK: --help
|
|
|
|
|
|
|
|
|
|
printf --help
|
|
|
|
|
echo
|
|
|
|
|
# CHECK: --help
|