I have the following printf
function:
$ printf '%s %s %s\t%s\n' 100644 blob 8e1e f1.txt 100644 blob 9de7 f2.txt | git mktree
Can anyone please explain what it produces and why? I expected to have equal number of formatting options %s
for each argument string but I have a lot more arguments strings here.
Best Answer
The format is reused as many times as needed to display all arguments. If there are too few arguments, the missing arguments are treated as empty strings.
Examples
Here is an example of a format that specifies two arguments but only one is provided:
Here is the same format, this time provided with one too many arguments:
Here is the example from the question in which the format expects four arguments. Since eight arguments are provided the entire format is used twice:
Documentation
From man bash: