implementation of printf '%N$' numbered argument conversion specifier, compatible with coreutils

This commit is contained in:
Chet Ramey
2025-12-05 15:50:38 -05:00
parent 5a104e96d8
commit f27bf94a79
29 changed files with 2012 additions and 1428 deletions
+30 -11
View File
@@ -1689,6 +1689,9 @@ PPAARRAAMMEETTEERRSS
The "+=" operator appends to an array variable when assigning using the
compound assignment syntax; see PPAARRAAMMEETTEERRSS above.
If one of the word expansions in a compound array assignment unsets the
variable, the results are unspecified.
An array element is referenced using ${_n_a_m_e[_s_u_b_s_c_r_i_p_t]}. The braces
are required to avoid conflicts with pathname expansion. If _s_u_b_s_c_r_i_p_t
is @@ or **, the word expands to all members of _n_a_m_e, unless noted in the
@@ -1899,7 +1902,7 @@ EEXXPPAANNSSIIOONN
_p_a_r_a_m_e_t_e_r is a positional parameter with more than one digit, or when
_p_a_r_a_m_e_t_e_r is followed by a character which is not to be interpreted as
part of its name. The _p_a_r_a_m_e_t_e_r is a shell parameter as described
above PPAARRAAMMEETTEERRSS) or an array reference (AArrrraayyss).
above (PPAARRAAMMEETTEERRSS) or an array reference (AArrrraayyss).
If the first character of _p_a_r_a_m_e_t_e_r is an exclamation point (!!), and
_p_a_r_a_m_e_t_e_r is not a _n_a_m_e_r_e_f, it introduces a level of indirection. BBaasshh
@@ -3729,6 +3732,7 @@ RREEAADDLLIINNEE
form
sseett _v_a_r_i_a_b_l_e_-_n_a_m_e _v_a_l_u_e
or using the bbiinndd builtin command (see SSHHEELLLL BBUUIILLTTIINN CCOOMMMMAANNDDSS below).
Except where noted, rreeaaddlliinnee variables can take the values OOnn or OOffff
@@ -4829,7 +4833,7 @@ RREEAADDLLIINNEE
fined, programmable completion performs rreeaaddlliinnee's default completion.
The options supplied to ccoommpplleettee and ccoommppoopptt can control how rreeaaddlliinnee
treats the completions. For instance, the _-_o _f_u_l_l_q_u_o_t_e option tells
treats the completions. For instance, the --oo ffuullllqquuoottee option tells
rreeaaddlliinnee to quote the matches as if they were filenames. See the de-
scription of ccoommpplleettee below for details.
@@ -5745,8 +5749,8 @@ SSHHEELLLL BBUUIILLTTIINN CCOOMMMMAANNDDSS
directories in which to search for _f_i_l_e_n_a_m_e. The default for
BBAASSHH__LLOOAADDAABBLLEESS__PPAATTHH is system-dependent, and may include "." to
force a search of the current directory. The --dd option will
delete a builtin previously loaded with --ff. If _-_s is used with
_-_f, the new builtin becomes a POSIX special builtin.
delete a builtin previously loaded with --ff. If --ss is used with
--ff, the new builtin becomes a POSIX special builtin.
If no options are supplied and a _n_a_m_e is not a shell builtin,
eennaabbllee will attempt to load _n_a_m_e from a shared object named
@@ -6164,7 +6168,7 @@ SSHHEELLLL BBUUIILLTTIINN CCOOMMMMAANNDDSS
last.
If the top element of the directory stack is modified, and the
_-_n option was not supplied, ppooppdd uses the ccdd builtin to change
--nn option was not supplied, ppooppdd uses the ccdd builtin to change
to the directory at the top of the stack. If the ccdd fails, ppooppdd
returns a non-zero value.
@@ -6232,12 +6236,27 @@ SSHHEELLLL BBUUIILLTTIINN CCOOMMMMAANNDDSS
is the numeric value of the following character, using the cur-
rent locale.
The _f_o_r_m_a_t is reused as necessary to consume all of the _a_r_g_u_-
Format specifiers may apply to the _nth argument rather than the
next sequential argument. In this case, the '%' in the format
specifier is replaced by the sequence "%_n$", where _n is a deci-
mal integer greater than 0, giving the argument number to use as
the operand. The format string should not mix numbered and un-
numbered argument specifiers, though this is allowed. Unnum-
bered argument specifiers always refer to the next argument fol-
lowing the last argument consumed by an unnumbered specifier;
numbered argument specifiers refer to absolute positions in the
argument list.
The _f_o_r_m_a_t is reused as necessary to consume all of the _a_r_g_u_-
_m_e_n_t_s. If the _f_o_r_m_a_t requires more _a_r_g_u_m_e_n_t_s than are supplied,
the extra format specifications behave as if a zero value or
null string, as appropriate, had been supplied. The return
value is zero on success, non-zero if an invalid option is sup-
plied or a write or assignment error occurs.
the extra format specifications behave as if a zero value or
null string, as appropriate, had been supplied. If _f_o_r_m_a_t is
reused, a numbered argument specifier "%_n$" refers to the _nth
argument following the highest numbered argument consumed by the
previous use of _f_o_r_m_a_t.
The return value is zero on success, non-zero if an invalid op-
tion is supplied or a write or assignment error occurs.
ppuusshhdd [--nn] [+_n] [-_n]
ppuusshhdd [--nn] [_d_i_r]
@@ -7555,4 +7574,4 @@ BBUUGGSS
Array variables may not (yet) be exported.
GNU Bash 5.3 2025 October 6 _B_A_S_H(1)
GNU Bash 5.3 2025 December 2 _B_A_S_H(1)