From: Brandon Casey <>

Old Bash (3.0) which is distributed with RHEL 4.X and other ancient
platforms that are still in wide use, do not have a printf that
supports -v.  Neither does Zsh (which is already handled in the code).

As suggested by Junio, let's test whether printf supports the -v
option and store the result.  Then later, we can use it to
determine whether 'printf -v' can be used, or whether printf
must be called in a subshell.

Signed-off-by: Brandon Casey <>

On 8/21/2013 6:27 PM, Junio C Hamano wrote:> Brandon Casey <> 
>> Why is "${var-}" necessary?  Wouldn't that be equivalent to "${var}"
>> or "$var"?
> set -u

Ah.  Thanks.  Updated.  Also minor tweak to use [ ] instead of test ...
to conform with the rest of the script.


 contrib/completion/ | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/contrib/completion/ b/contrib/completion/
index a81ef5a..ca7fb35 100644
--- a/contrib/completion/
+++ b/contrib/completion/
@@ -84,6 +84,10 @@
 # the colored output of "git status -sb" and are available only when
 # using __git_ps1 for PROMPT_COMMAND or precmd.
+# check whether printf supports -v
+printf -v __git_printf_supports_v -- '%s' yes >/dev/null 2>&1
 # stores the divergence from upstream in $p
 __git_ps1_show_upstream ()
@@ -433,10 +437,10 @@ __git_ps1 ()
        local gitstring="$c${b##refs/heads/}${f:+$z$f}$r$p"
        if [ $pcmode = yes ]; then
-               if [[ -n ${ZSH_VERSION-} ]]; then
-                       gitstring=$(printf -- "$printf_format" "$gitstring")
-               else
+               if [ "${__git_printf_supports_v-}" = yes ]; then
                        printf -v gitstring -- "$printf_format" "$gitstring"
+               else
+                       gitstring=$(printf -- "$printf_format" "$gitstring")

This email message is for the sole use of the intended recipient(s) and may 
confidential information.  Any unauthorized review, use, disclosure or 
is prohibited.  If you are not the intended recipient, please contact the 
sender by
reply email and destroy all copies of the original message.
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to
More majordomo info at

Reply via email to