summaryrefslogtreecommitdiff
path: root/src/printf.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/printf.c')
-rw-r--r--src/printf.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/src/printf.c b/src/printf.c
index 3e68b995f..a24494631 100644
--- a/src/printf.c
+++ b/src/printf.c
@@ -41,6 +41,10 @@
%b = print an argument string, interpreting backslash escapes,
except that octal escapes are of the form \0 or \0ooo.
+ %q = print an argument string in a format that can be
+ reused as shell input. Escaped characters used the proposed
+ POSIX $'' syntax supported by most shells.
+
The 'format' argument is re-used as many times as necessary
to convert all of the given arguments.
@@ -124,7 +128,9 @@ FORMAT controls the output as in C printf. Interpreted sequences are:\n\
%% a single %\n\
%b ARGUMENT as a string with '\\' escapes interpreted,\n\
except that octal escapes are of the form \\0 or \\0NNN\n\
-\n\
+ %q ARGUMENT is printed in a format that can be reused as shell input,\n\
+ escaping non-printable characters with the proposed POSIX $'' syntax.\
+\n\n\
and all C format specifications ending with one of diouxXfeEgGcs, with\n\
ARGUMENTs converted to proper type first. Variable widths are handled.\n\
"), stdout);
@@ -506,6 +512,18 @@ print_formatted (const char *format, int argc, char **argv)
break;
}
+ if (*f == 'q')
+ {
+ if (argc > 0)
+ {
+ fputs (quotearg_style (shell_escape_quoting_style, *argv),
+ stdout);
+ ++argv;
+ --argc;
+ }
+ break;
+ }
+
memset (ok, 0, sizeof ok);
ok['a'] = ok['A'] = ok['c'] = ok['d'] = ok['e'] = ok['E'] =
ok['f'] = ok['F'] = ok['g'] = ok['G'] = ok['i'] = ok['o'] =