Re: [PATCH] Replace "echo -n" with printf in shell scripts.

9 messages, 7 authors, 2016-06-15 · open the first message on its own page

Re: [PATCH] Replace "echo -n" with printf in shell scripts.

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:42:49

Jason Riedy [off-list ref] writes:
Not all echos know -n.  This was causing a test failure in
t5401-update-hooks.sh, but not t3800-mktag.sh for some reason.
We have done this already so it might be too late to raise this
question, but does everybody have printf?
quoted hunk
diff --git a/contrib/remotes2config.sh b/contrib/remotes2config.sh
index 25901e2..b996996 100644
--- a/contrib/remotes2config.sh
+++ b/contrib/remotes2config.sh
@@ -11,7 +11,7 @@ if [ -d "$GIT_DIR"/remotes ]; then
 	{
 		cd "$GIT_DIR"/remotes
 		ls | while read f; do
-			name=$(echo -n "$f" | tr -c "A-Za-z0-9" ".")
+			name=$(printf "$f" | tr -c "A-Za-z0-9" ".")
This should almost be safe as no sane person would have a remote
whose name is 'foo%s'...

Re: [PATCH] Replace "echo -n" with printf in shell scripts.

From: Jason Riedy <hidden>
Date: 2016-06-15 22:42:49

And Junio C Hamano writes:
We have done this already so it might be too late to raise this
question, but does everybody have printf?
It's in the Single Unix Spec as the alternative to non-portable
echo uses:
  http://opengroup.org/onlinepubs/007908799/xcu/echo.html#tag_001_014_525
And no one has complained so far...
quoted
-			name=$(echo -n "$f" | tr -c "A-Za-z0-9" ".")
+			name=$(printf "$f" | tr -c "A-Za-z0-9" ".")
This should almost be safe as no sane person would have a remote
whose name is 'foo%s'...
Forgot about that, thanks.  It should be printf "%s" "$f".

Jason

Re: [PATCH] Replace "echo -n" with printf in shell scripts.

From: Eric Blake <hidden>
Date: 2016-06-15 22:42:49

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

According to Junio C Hamano on 1/15/2007 7:46 PM:
quoted
-			name=$(echo -n "$f" | tr -c "A-Za-z0-9" ".")
+			name=$(printf "$f" | tr -c "A-Za-z0-9" ".")
This should almost be safe as no sane person would have a remote
whose name is 'foo%s'...
Why not go all the way, and make it safe, regardless of embedded %,
embedded \, or leading -?

name=$(printf -- %s "$f" | tr -c "A-Za-z0-9" ".")

- --
Don't work too hard, make some time for fun as well!

Eric Blake             ebb9@byu.net
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFrEHw84KuGfSFAYARAlH9AJ9q3atCpSVBTg0SVhZ4DQ9T7qiqEQCfe9D2
bGTfwnvW6uN1ky6ncWYgkgc=
=P9t5
-----END PGP SIGNATURE-----

Re: [PATCH] Replace "echo -n" with printf in shell scripts.

From: Horst H. von Brand <hidden>
Date: 2016-06-15 22:42:49

Junio C Hamano [off-list ref] wrote:
Jason Riedy [off-list ref] writes:
quoted
Not all echos know -n.  This was causing a test failure in
t5401-update-hooks.sh, but not t3800-mktag.sh for some reason.
We have done this already so it might be too late to raise this
question, but does everybody have printf?
Here (Fedora rawhide) /usr/bin/printf is part of coreutils.
-- 
Dr. Horst H. von Brand                   User #22616 counter.li.org
Departamento de Informatica                    Fono: +56 32 2654431
Universidad Tecnica Federico Santa Maria             +56 32 2654239
Casilla 110-V, Valparaiso, Chile               Fax:  +56 32 2797513

Re: [PATCH] Replace "echo -n" with printf in shell scripts.

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:42:49

"Horst H. von Brand" [off-list ref] writes:
Junio C Hamano [off-list ref] wrote:
quoted
Jason Riedy [off-list ref] writes:
quoted
Not all echos know -n.  This was causing a test failure in
t5401-update-hooks.sh, but not t3800-mktag.sh for some reason.
We have done this already so it might be too late to raise this
question, but does everybody have printf?
Here (Fedora rawhide) /usr/bin/printf is part of coreutils.
I am reasonably sure people on Linux land would be fine
regardless of distros, but thanks anyway.

The problematic are less common ones, ranging from (not so less
common) OSX, Solaris to (much less common) AIX that some people
seem to run git on (or at least compile git for).

Re: [PATCH] Replace "echo -n" with printf in shell scripts.

From: Brian Gernhardt <hidden>
Date: 2016-06-15 22:42:49

On Jan 17, 2007, at 12:33 PM, Junio C Hamano wrote:
The problematic are less common ones, ranging from (not so less
common) OSX, Solaris to (much less common) AIX that some people
seem to run git on (or at least compile git for).
At least as far a OS X goes, it's installed on my machine (10.4.8)  
as /usr/bin/printf.  I don't know if it's part of the Xcode packages,  
the "BSD Subsystem", or the core OS but I have a hard time imagining  
someone who didn't have them all installed using GIT.

Also, it's man page identifies itself as
"PRINTF(1)                 BSD General Commands Manual                 
PRINTF(1)"
so most, if not all, flavors of BSD and BSD-like should be alright.

~~ Brian

Re: [PATCH] Replace "echo -n" with printf in shell scripts.

From: Julian Phillips <hidden>
Date: 2016-06-15 22:42:49

On Wed, 17 Jan 2007, Junio C Hamano wrote:
"Horst H. von Brand" [off-list ref] writes:
quoted
Junio C Hamano [off-list ref] wrote:
quoted
Jason Riedy [off-list ref] writes:
quoted
Not all echos know -n.  This was causing a test failure in
t5401-update-hooks.sh, but not t3800-mktag.sh for some reason.
We have done this already so it might be too late to raise this
question, but does everybody have printf?
Here (Fedora rawhide) /usr/bin/printf is part of coreutils.
I am reasonably sure people on Linux land would be fine
regardless of distros, but thanks anyway.

The problematic are less common ones, ranging from (not so less
common) OSX, Solaris to (much less common) AIX that some people
seem to run git on (or at least compile git for).
printf is a bash builtin ... not sure about other shells.

-- 
Julian

  ---
A lifetime isn't nearly long enough to figure out what it's all about.

Re: [PATCH] Replace "echo -n" with printf in shell scripts.

From: Horst H. von Brand <hidden>
Date: 2016-06-15 22:42:49

Julian Phillips [off-list ref] wrote:

[...]
printf is a bash builtin ... not sure about other shells.
It's a builtin in zsh and in ksh, and /not/ in tcsh here (Fedora rawhide)

zsh-4.2.6-3.fc7
ksh-20060214-1.1
tcsh-6.14-13

It might be special configuration, but as they are mentioned in the manpages
I'd guess not.
-- 
Dr. Horst H. von Brand                   User #22616 counter.li.org
Departamento de Informatica                    Fono: +56 32 2654431
Universidad Tecnica Federico Santa Maria             +56 32 2654239
Casilla 110-V, Valparaiso, Chile               Fax:  +56 32 2797513

Re: [PATCH] Replace "echo -n" with printf in shell scripts.

From: Simon 'corecode' Schubert <hidden>
Date: 2016-06-15 22:42:49

Junio C Hamano wrote:
quoted
quoted
We have done this already so it might be too late to raise this
question, but does everybody have printf?
The problematic are less common ones, ranging from (not so less
common) OSX, Solaris to (much less common) AIX that some people
seem to run git on (or at least compile git for).
printf(1) is part of POSIX/SUSv3, so systems *should* have it.

cheers
  simon

-- 
Serve - BSD     +++  RENT this banner advert  +++    ASCII Ribbon   /"\
Work - Mac      +++  space for low €€€ NOW!1  +++      Campaign     \ /
Party Enjoy Relax   |   http://dragonflybsd.org      Against  HTML   \
Dude 2c 2 the max   !   http://golden-apple.biz       Mail + News   / \
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help