printfwhich sends its output to
stdout, this function takes a variable name to store its output.
bashversion 3.1 or higher, the function is defined to use
printf -v varname ...because it is faster (
bashhas not optimized for the case of
varname=$( printf ... )). On FreeBSD,
/bin/shhas been optimized for the case of
varname=$( printf ... )and it runs faster than bash's
printf -v varname ...syntax.
varname=$( ... )results in a sub-shell, impacting performance. On FreeBSD you can rely on the fact that calling
printfin a sub-shell does not impact performance as it does in
bash. Shells that neither provide
printf -v varname ...like
bashnor optimize for
printfin a sub-shell like FreeBSD may be slower.