
On 2011-11-12 20:13, Tim Connors wrote:
On Fri, 11 Nov 2011, Trent W. Buck wrote:
Matthew Cengia wrote:
mattcen@tony:tmp$ files=$(for file in *; do printf "%s\n" "$file"; done)
Ahem. If you can guarantee bash, I humbly suggest using an array. The syntax is something like
xs=(*.mp3) # array of glob matches printf '"%s"\n' "${xs[@]}" # example use thereof
Hah!
Where in the documentation does it specify that printf prints lines for each arg not sucked up by format strings, eg:
From the Bash manpage, in the printf section: The format is reused as necessary to consume all of the arguments. Alternatively, for /usr/bin/printf, 'info coreutils "printf invocation"' shows: * The FORMAT argument is reused as necessary to convert all the given ARGUMENTs.
printf "%s - %s" 1 2 3 1 - 2 3 -
?
That's kinda neat, but kinda dangerous and contrary to the printf() I'm used to (which just ignores extra args and segfaults if there aren't enough of them).
I don't see any danger; if the *expected* behaviour was that of /usr/bin/prinf and Bash's inbuild printf, then yes, perhaps printf(3) can become dangerous, but any C programmer who has written anything more complex than a Hello World program should probably know better :). -- Regards, Matthew Cengia