All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Replace "echo -n" with printf in shell scripts.
@ 2007-01-16  1:31 Jason Riedy
  2007-01-16  2:46 ` Junio C Hamano
  0 siblings, 1 reply; 11+ messages in thread
From: Jason Riedy @ 2007-01-16  1:31 UTC (permalink / raw)
  To: git

Not all echos know -n.  This was causing a test failure in
t5401-update-hooks.sh, but not t3800-mktag.sh for some reason.

Signed-off-by: Jason Riedy <ejr@cs.berkeley.edu>
---
 contrib/remotes2config.sh |    2 +-
 git-quiltimport.sh        |    2 +-
 git-reset.sh              |    2 +-
 t/t3800-mktag.sh          |    2 +-
 t/t5401-update-hooks.sh   |    4 ++--
 t/t6023-merge-file.sh     |    2 +-
 6 files changed, 7 insertions(+), 7 deletions(-)

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" ".")
 			sed -n \
 			-e "s/^URL: \(.*\)$/remote.$name.url \1 ./p" \
 			-e "s/^Pull: \(.*\)$/remote.$name.fetch \1 ^$ /p" \
diff --git a/git-quiltimport.sh b/git-quiltimport.sh
index 10135da..2ae1f20 100755
--- a/git-quiltimport.sh
+++ b/git-quiltimport.sh
@@ -89,7 +89,7 @@ for patch_name in $(cat "$QUILT_PATCHES/series" | grep -v '^#'); do
 			echo "No author found in $patch_name" >&2;
 			echo "---"
 			cat $tmp_msg
-			echo -n "Author: ";
+			printf "Author: ";
 			read patch_author
 
 			echo "$patch_author"
diff --git a/git-reset.sh b/git-reset.sh
index 91c7e6e..bf2a058 100755
--- a/git-reset.sh
+++ b/git-reset.sh
@@ -87,7 +87,7 @@ update_ref_status=$?
 case "$reset_type" in
 --hard )
 	test $update_ref_status = 0 && {
-		echo -n "HEAD is now at "
+		printf "HEAD is now at "
 		GIT_PAGER= git log --max-count=1 --pretty=oneline \
 			--abbrev-commit HEAD
 	}
diff --git a/t/t3800-mktag.sh b/t/t3800-mktag.sh
index 5b23b77..ede4d42 100755
--- a/t/t3800-mktag.sh
+++ b/t/t3800-mktag.sh
@@ -88,7 +88,7 @@ check_verify_failure '"type" line label check'
 #  5. type line eol check
 
 echo "object 779e9b33986b1c2670fff52c5067603117b3e895" >tag.sig
-echo -n "type tagsssssssssssssssssssssssssssssss" >>tag.sig
+printf "type tagsssssssssssssssssssssssssssssss" >>tag.sig
 
 cat >expect.pat <<EOF
 ^error: char48: .*"[\]n"$
diff --git a/t/t5401-update-hooks.sh b/t/t5401-update-hooks.sh
index cd8cee6..0514056 100755
--- a/t/t5401-update-hooks.sh
+++ b/t/t5401-update-hooks.sh
@@ -23,7 +23,7 @@ test_expect_success setup '
 cat >victim/.git/hooks/update <<'EOF'
 #!/bin/sh
 echo "$@" >$GIT_DIR/update.args
-read x; echo -n "$x" >$GIT_DIR/update.stdin
+read x; printf "$x" >$GIT_DIR/update.stdin
 echo STDOUT update
 echo STDERR update >&2
 EOF
@@ -32,7 +32,7 @@ chmod u+x victim/.git/hooks/update
 cat >victim/.git/hooks/post-update <<'EOF'
 #!/bin/sh
 echo "$@" >$GIT_DIR/post-update.args
-read x; echo -n "$x" >$GIT_DIR/post-update.stdin
+read x; printf "$x" >$GIT_DIR/post-update.stdin
 echo STDOUT post-update
 echo STDERR post-update >&2
 EOF
diff --git a/t/t6023-merge-file.sh b/t/t6023-merge-file.sh
index 1c21d8c..f3cd3db 100644
--- a/t/t6023-merge-file.sh
+++ b/t/t6023-merge-file.sh
@@ -52,7 +52,7 @@ super aquam refectionis educavit me;
 animam meam convertit,
 deduxit me super semitas jusitiae,
 EOF
-echo -n "propter nomen suum." >> new4.txt
+printf "propter nomen suum." >> new4.txt
 
 cp new1.txt test.txt
 test_expect_success "merge without conflict" \
-- 
1.5.0.rc1.gf4b6c

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH] Replace "echo -n" with printf in shell scripts.
  2007-01-16  1:31 [PATCH] Replace "echo -n" with printf in shell scripts Jason Riedy
@ 2007-01-16  2:46 ` Junio C Hamano
  2007-01-16  3:03   ` Jason Riedy
                     ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Junio C Hamano @ 2007-01-16  2:46 UTC (permalink / raw)
  To: Jason Riedy; +Cc: git

Jason Riedy <ejr@EECS.Berkeley.EDU> 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?

> 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'...

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] Replace "echo -n" with printf in shell scripts.
  2007-01-16  2:46 ` Junio C Hamano
@ 2007-01-16  3:03   ` Jason Riedy
  2007-01-16  3:09   ` Eric Blake
  2007-01-17 16:29   ` Horst H. von Brand
  2 siblings, 0 replies; 11+ messages in thread
From: Jason Riedy @ 2007-01-16  3:03 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

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...

> > -			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

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] Replace "echo -n" with printf in shell scripts.
  2007-01-16  2:46 ` Junio C Hamano
  2007-01-16  3:03   ` Jason Riedy
@ 2007-01-16  3:09   ` Eric Blake
  2007-01-17 16:29   ` Horst H. von Brand
  2 siblings, 0 replies; 11+ messages in thread
From: Eric Blake @ 2007-01-16  3:09 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Jason Riedy, git

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

According to Junio C Hamano on 1/15/2007 7:46 PM:
>> -			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-----

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] Replace "echo -n" with printf in shell scripts.
  2007-01-16  2:46 ` Junio C Hamano
  2007-01-16  3:03   ` Jason Riedy
  2007-01-16  3:09   ` Eric Blake
@ 2007-01-17 16:29   ` Horst H. von Brand
  2007-01-17 17:33     ` Junio C Hamano
  2 siblings, 1 reply; 11+ messages in thread
From: Horst H. von Brand @ 2007-01-17 16:29 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Jason Riedy, git

Junio C Hamano <junkio@cox.net> wrote:
> Jason Riedy <ejr@EECS.Berkeley.EDU> 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?

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

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] Replace "echo -n" with printf in shell scripts.
  2007-01-17 16:29   ` Horst H. von Brand
@ 2007-01-17 17:33     ` Junio C Hamano
  2007-01-17 18:00       ` Brian Gernhardt
                         ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Junio C Hamano @ 2007-01-17 17:33 UTC (permalink / raw)
  To: Horst H. von Brand; +Cc: git

"Horst H. von Brand" <vonbrand@inf.utfsm.cl> writes:

> Junio C Hamano <junkio@cox.net> wrote:
>> Jason Riedy <ejr@EECS.Berkeley.EDU> 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?
>
> 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).

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] Replace "echo -n" with printf in shell scripts.
  2007-01-17 17:33     ` Junio C Hamano
@ 2007-01-17 18:00       ` Brian Gernhardt
  2007-01-17 18:07       ` Julian Phillips
  2007-01-18  0:02       ` Simon 'corecode' Schubert
  2 siblings, 0 replies; 11+ messages in thread
From: Brian Gernhardt @ 2007-01-17 18:00 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Horst H. von Brand, git


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

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] Replace "echo -n" with printf in shell scripts.
  2007-01-17 17:33     ` Junio C Hamano
  2007-01-17 18:00       ` Brian Gernhardt
@ 2007-01-17 18:07       ` Julian Phillips
  2007-01-17 20:17         ` Horst H. von Brand
  2007-01-18  0:02       ` Simon 'corecode' Schubert
  2 siblings, 1 reply; 11+ messages in thread
From: Julian Phillips @ 2007-01-17 18:07 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Horst H. von Brand, git

On Wed, 17 Jan 2007, Junio C Hamano wrote:

> "Horst H. von Brand" <vonbrand@inf.utfsm.cl> writes:
>
>> Junio C Hamano <junkio@cox.net> wrote:
>>> Jason Riedy <ejr@EECS.Berkeley.EDU> 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?
>>
>> 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.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] Replace "echo -n" with printf in shell scripts.
  2007-01-17 18:07       ` Julian Phillips
@ 2007-01-17 20:17         ` Horst H. von Brand
  0 siblings, 0 replies; 11+ messages in thread
From: Horst H. von Brand @ 2007-01-17 20:17 UTC (permalink / raw)
  To: Julian Phillips; +Cc: Junio C Hamano, git

Julian Phillips <julian@quantumfyre.co.uk> 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

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] Replace "echo -n" with printf in shell scripts.
  2007-01-17 17:33     ` Junio C Hamano
  2007-01-17 18:00       ` Brian Gernhardt
  2007-01-17 18:07       ` Julian Phillips
@ 2007-01-18  0:02       ` Simon 'corecode' Schubert
  2007-01-18  0:13         ` Junio C Hamano
  2 siblings, 1 reply; 11+ messages in thread
From: Simon 'corecode' Schubert @ 2007-01-18  0:02 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Horst H. von Brand, git

[-- Attachment #1: Type: text/plain, Size: 717 bytes --]

Junio C Hamano wrote:
>>> 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   / \


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 252 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] Replace "echo -n" with printf in shell scripts.
  2007-01-18  0:02       ` Simon 'corecode' Schubert
@ 2007-01-18  0:13         ` Junio C Hamano
  0 siblings, 0 replies; 11+ messages in thread
From: Junio C Hamano @ 2007-01-18  0:13 UTC (permalink / raw)
  To: Simon 'corecode' Schubert; +Cc: Horst H. von Brand, git

Simon 'corecode' Schubert <corecode@fs.ei.tum.de> writes:

> Junio C Hamano wrote:
>>>> 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.

A lot of the portability problem we suffered were about the
things that systems *should* have it.

Unfortunately a standard does not matter a whit on its own when
dealing with the real world.  That's why I muttered the above
even though I knew POSIX says you should have one.

We use POSIX as one of the yardsticks to see what we should stay
away (i.e. "that is not even in POSIX so let's not use it for
now"), and also how far we are willing to bend over (i.e. "any
reasonable system should have it; besides, it is in POSIX.
Let's use it -- it is so convenient -- and insane platforms can
screw themselves").

The key point in the latter is that "besides" is not "because".

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2007-01-18  0:24 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-01-16  1:31 [PATCH] Replace "echo -n" with printf in shell scripts Jason Riedy
2007-01-16  2:46 ` Junio C Hamano
2007-01-16  3:03   ` Jason Riedy
2007-01-16  3:09   ` Eric Blake
2007-01-17 16:29   ` Horst H. von Brand
2007-01-17 17:33     ` Junio C Hamano
2007-01-17 18:00       ` Brian Gernhardt
2007-01-17 18:07       ` Julian Phillips
2007-01-17 20:17         ` Horst H. von Brand
2007-01-18  0:02       ` Simon 'corecode' Schubert
2007-01-18  0:13         ` Junio C Hamano

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.