-
Notifications
You must be signed in to change notification settings - Fork 154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
printf %q broken with size specifier #1477
Comments
first of all, this repo is no longer under active development, please see #1475 for a possible longterm alternative where to raise ksh issues in the future. but to answer your question here nonetheless:
so making ksh's printf change behaviour by erroring out in the presence of a width qualifier seems not a good idea in my view. |
The output is correct, w.r.t what gets requested: max. 2 byte of the string to be printed ( |
sure. the question is "bug or feature" considering the declared purpose of the %q format -- that was the point the OP made. |
q refers to Quoted string, s to String, d to Decimal, ... Format specifiers are optional, allows one to format alias mangle the related operand. If one says, "I want max. 2 bytes of it", ksh just follows standards and prints not more than 2 bytes of it. Nothing wrong here. |
as said, I tend to agree but it remains matter of taste. and as the OP pointed out, gnu coreutils decided to handle it differently, seemingly (not tested myself) |
GNU tools, bash, ... - did they ever read any specs before implementing things [halfhearted] ? ;-) |
good point. let's leave it at that :) |
korn man page printf section says:
%q A %q format can be used instead of %s to cause the resulting string to be quoted in a manner than can be reinput to the shell.
$ printf '%q\n' "a'b"
$'a'b'
$ printf '%.2q\n' "a'b"
$'
definitely not suitable for re-input to the shell.
GNU Coreutils printf %q refuses to accept size specifiers for %q:
$ /usr/bin/printf '%.2q\n' "a'b"
/usr/bin/printf: %.2q: invalid conversion specification
bash has the same bug. Their response is "programmer error" "Don't do that" but I think the error is with the bash maintainers, and like the GNU Coreutils maintainers they should not let bash do that. If the shell maintainers who know about this bug won't "not do that" how can their users who don't know about it be expected to "not do that"?
%q should not renege on it's guarantees of suitability for re-use by the shell.
The text was updated successfully, but these errors were encountered: