# [PATCH] t4030: Don't use echo -n

15 messages from 2008-10-30 to 2008-11-03. Participants: Brian Gernhardt, Ian Hilt, Junio C Hamano, Steve Folly, Shawn O. Pearce, Jeff King, Pierre Habouzit, Francis Galiegue, Johannes Schindelin, Mike Ralphson.
Thread: https://gitlist.dev/t/16101

## Brian Gernhardt, 2008-10-30 22:12

Subject: [PATCH] t4030: Don't use echo -n
Message-ID: <1225404776-51748-1-git-send-email-benji@silverinsanity.com>
URL: https://gitlist.dev/e/1225404776-51748-1-git-send-email-benji%40silverinsanity.com

```
Signed-off-by: Brian Gernhardt <benji@silverinsanity.com>
---
 t/t4030-diff-textconv.sh |    5 ++---
 1 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/t/t4030-diff-textconv.sh b/t/t4030-diff-textconv.sh
index 3945731..7ec244f 100755
--- a/t/t4030-diff-textconv.sh
+++ b/t/t4030-diff-textconv.sh
@@ -96,16 +96,15 @@ cat >expect.typechange <<'EOF'
 -1
 diff --git a/file b/file
 new file mode 120000
-index ad8b3d2..67be421
+index ad8b3d2..8e4020b
 --- /dev/null
 +++ b/file
 @@ -0,0 +1 @@
 +frotz
-\ No newline at end of file
 EOF
 # make a symlink the hard way that works on symlink-challenged file systems
 test_expect_success 'textconv does not act on symlinks' '
-	echo -n frotz > file &&
+	echo frotz > file &&
 	git add file &&
 	git ls-files -s | sed -e s/100644/120000/ |
 		git update-index --index-info &&
-- 
1.6.0.3.523.g304d0

```

## Ian Hilt, 2008-10-30 23:52

Subject: Re: [PATCH] t4030: Don't use echo -n
Message-ID: <20081030235215.GB18221@sys-0.hiltweb.site>
URL: https://gitlist.dev/e/20081030235215.GB18221%40sys-0.hiltweb.site
In-Reply-To: <1225404776-51748-1-git-send-email-benji@silverinsanity.com>

```
On Thu, Oct 30, 2008 at 06:12:56PM -0400, Brian Gernhardt wrote:
> Signed-off-by: Brian Gernhardt <benji@silverinsanity.com>

No commit message???

> ---
>  t/t4030-diff-textconv.sh |    5 ++---
>  1 files changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/t/t4030-diff-textconv.sh b/t/t4030-diff-textconv.sh
> index 3945731..7ec244f 100755
> --- a/t/t4030-diff-textconv.sh
> +++ b/t/t4030-diff-textconv.sh
> @@ -96,16 +96,15 @@ cat >expect.typechange <<'EOF'
>  -1
>  diff --git a/file b/file
>  new file mode 120000
> -index ad8b3d2..67be421
> +index ad8b3d2..8e4020b
>  --- /dev/null
>  +++ b/file
>  @@ -0,0 +1 @@
>  +frotz
> -\ No newline at end of file
>  EOF
>  # make a symlink the hard way that works on symlink-challenged file systems
>  test_expect_success 'textconv does not act on symlinks' '
> -	echo -n frotz > file &&
> +	echo frotz > file &&
>  	git add file &&
>  	git ls-files -s | sed -e s/100644/120000/ |
>  		git update-index --index-info &&
> -- 
> 1.6.0.3.523.g304d0

This doesn't apply for me.  My tip is up-to-date, but it doesn't even have
this file it t/.

A little bewildered,

	Ian

```

## Brian Gernhardt, 2008-10-31 05:02

Subject: Re: [PATCH] t4030: Don't use echo -n
Message-ID: <8A4A84EC-51F7-4038-957C-CCA5C00E5977@silverinsanity.com>
URL: https://gitlist.dev/e/8A4A84EC-51F7-4038-957C-CCA5C00E5977%40silverinsanity.com
In-Reply-To: <20081030235215.GB18221@sys-0.hiltweb.site>

```

On Oct 30, 2008, at 7:52 PM, Ian Hilt wrote:

> On Thu, Oct 30, 2008 at 06:12:56PM -0400, Brian Gernhardt wrote:
>> Signed-off-by: Brian Gernhardt <benji@silverinsanity.com>
>
> No commit message???
>>

"Don't use echo -n" seemed simple enough to me, as it's the only thing  
it does.  And the reason is that echo -n isn't portable, as has been  
determined previously in git.  I'll update this and use the better  
replacement "printf" anyway.

> This doesn't apply for me.  My tip is up-to-date, but it doesn't  
> even have
> this file it t/.

This is based on next and is for a file that isn't in master.

~~ Brian

```

## Brian Gernhardt, 2008-10-31 05:09

Subject: [PATCH] Avoid using non-portable `echo -n` in tests.
Message-ID: <1225429753-70109-1-git-send-email-benji@silverinsanity.com>
URL: https://gitlist.dev/e/1225429753-70109-1-git-send-email-benji%40silverinsanity.com
In-Reply-To: <8A4A84EC-51F7-4038-957C-CCA5C00E5977@silverinsanity.com>

```
Not all /bin/sh have a builtin echo that recognizes -n.  Using printf
is far more portable.

Discovered on OS X 10.5.5 in t4030-diff-textconv.sh and changed in all
the test scripts.

Signed-off-by: Brian Gernhardt <benji@silverinsanity.com>
---
 t/t2005-checkout-index-symlinks.sh |    2 +-
 t/t2102-update-index-symlinks.sh   |    4 ++--
 t/t4030-diff-textconv.sh           |    2 +-
 t/t6025-merge-symlinks.sh          |    4 ++--
 t/t9400-git-cvsserver-server.sh    |    2 +-
 5 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/t/t2005-checkout-index-symlinks.sh b/t/t2005-checkout-index-symlinks.sh
index ed12c4d..9fa5610 100755
--- a/t/t2005-checkout-index-symlinks.sh
+++ b/t/t2005-checkout-index-symlinks.sh
@@ -13,7 +13,7 @@ file if core.symlinks is false.'
 test_expect_success \
 'preparation' '
 git config core.symlinks false &&
-l=$(echo -n file | git hash-object -t blob -w --stdin) &&
+l=$(printf file | git hash-object -t blob -w --stdin) &&
 echo "120000 $l	symlink" | git update-index --index-info'
 
 test_expect_success \
diff --git a/t/t2102-update-index-symlinks.sh b/t/t2102-update-index-symlinks.sh
index f195aef..1ed44ee 100755
--- a/t/t2102-update-index-symlinks.sh
+++ b/t/t2102-update-index-symlinks.sh
@@ -13,12 +13,12 @@ even if a plain file is in the working tree if core.symlinks is false.'
 test_expect_success \
 'preparation' '
 git config core.symlinks false &&
-l=$(echo -n file | git hash-object -t blob -w --stdin) &&
+l=$(printf file | git hash-object -t blob -w --stdin) &&
 echo "120000 $l	symlink" | git update-index --index-info'
 
 test_expect_success \
 'modify the symbolic link' '
-echo -n new-file > symlink &&
+printf new-file > symlink &&
 git update-index symlink'
 
 test_expect_success \
diff --git a/t/t4030-diff-textconv.sh b/t/t4030-diff-textconv.sh
index 3945731..a235955 100755
--- a/t/t4030-diff-textconv.sh
+++ b/t/t4030-diff-textconv.sh
@@ -105,7 +105,7 @@ index ad8b3d2..67be421
 EOF
 # make a symlink the hard way that works on symlink-challenged file systems
 test_expect_success 'textconv does not act on symlinks' '
-	echo -n frotz > file &&
+	printf frotz > file &&
 	git add file &&
 	git ls-files -s | sed -e s/100644/120000/ |
 		git update-index --index-info &&
diff --git a/t/t6025-merge-symlinks.sh b/t/t6025-merge-symlinks.sh
index 53892a5..433c4de 100755
--- a/t/t6025-merge-symlinks.sh
+++ b/t/t6025-merge-symlinks.sh
@@ -18,11 +18,11 @@ git add file &&
 git commit -m initial &&
 git branch b-symlink &&
 git branch b-file &&
-l=$(echo -n file | git hash-object -t blob -w --stdin) &&
+l=$(printf file | git hash-object -t blob -w --stdin) &&
 echo "120000 $l	symlink" | git update-index --index-info &&
 git commit -m master &&
 git checkout b-symlink &&
-l=$(echo -n file-different | git hash-object -t blob -w --stdin) &&
+l=$(printf file-different | git hash-object -t blob -w --stdin) &&
 echo "120000 $l	symlink" | git update-index --index-info &&
 git commit -m b-symlink &&
 git checkout b-file &&
diff --git a/t/t9400-git-cvsserver-server.sh b/t/t9400-git-cvsserver-server.sh
index c1850d2..f6a2dbd 100755
--- a/t/t9400-git-cvsserver-server.sh
+++ b/t/t9400-git-cvsserver-server.sh
@@ -424,7 +424,7 @@ cd "$WORKDIR"
 test_expect_success 'cvs update (-p)' '
     touch really-empty &&
     echo Line 1 > no-lf &&
-    echo -n Line 2 >> no-lf &&
+    printf Line 2 >> no-lf &&
     git add really-empty no-lf &&
     git commit -q -m "Update -p test" &&
     git push gitcvs.git >/dev/null &&
-- 
1.6.0.3.757.g1e5a4

```

## Junio C Hamano, 2008-10-31 08:15

Subject: Re: [PATCH] Avoid using non-portable `echo -n` in tests.
Message-ID: <7vy70589jc.fsf@gitster.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vy70589jc.fsf%40gitster.siamese.dyndns.org
In-Reply-To: <1225429753-70109-1-git-send-email-benji@silverinsanity.com>

```
Brian Gernhardt <benji@silverinsanity.com> writes:

> Not all /bin/sh have a builtin echo that recognizes -n.  Using printf
> is far more portable.

This is much better (minor nit: we do not care if echo is built-in or
/bin/echo); the point of t4030 is to produce an incomplete line ;-).

Will queue, thanks.

```

## Junio C Hamano, 2008-10-31 08:20

Subject: Re: [PATCH] Avoid using non-portable `echo -n` in tests.
Message-ID: <7vtzat89br.fsf@gitster.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vtzat89br.fsf%40gitster.siamese.dyndns.org
In-Reply-To: <1225429753-70109-1-git-send-email-benji@silverinsanity.com>

```
Brian Gernhardt <benji@silverinsanity.com> writes:

> Not all /bin/sh have a builtin echo that recognizes -n.  Using printf
> is far more portable.
>
> Discovered on OS X 10.5.5 in t4030-diff-textconv.sh and changed in all
> the test scripts.

I had an impression that OS X was BSDish.  Wasn't "echo -n" a BSDism?

```

## Steve Folly, 2008-10-31 09:36

Subject: Re: [PATCH] Avoid using non-portable `echo-n` in tests.
Message-ID: <loom.20081031T093317-846@post.gmane.org>
URL: https://gitlist.dev/e/loom.20081031T093317-846%40post.gmane.org
In-Reply-To: <7vtzat89br.fsf@gitster.siamese.dyndns.org>

```
Junio C Hamano <gitster <at> pobox.com> writes:

> 
> Brian Gernhardt <benji <at> silverinsanity.com> writes:
> 
> > Not all /bin/sh have a builtin echo that recognizes -n.  Using printf
> > is far more portable.
> >
> > Discovered on OS X 10.5.5 in t4030-diff-textconv.sh and changed in all
> > the test scripts.
> 
> I had an impression that OS X was BSDish.  Wasn't "echo -n" a BSDism?
> 

FYI, "man echo" on OS X 10.5.5 has this to say...

     The following option is available:

     -n    Do not print the trailing newline character.  This may also be
           achieved by appending `\c' to the end of the string, as is done by
           iBCS2 compatible systems.  Note that this option as well as the
           effect of `\c' are implementation-defined in IEEE Std 1003.1-2001
           (``POSIX.1'') as amended by Cor. 1-2002.  Applications aiming for
           maximum portability are strongly encouraged to use printf(1) to
           suppress the newline character.

     Some shells may provide a builtin echo command which is similar or iden-
     tical to this utility.  Most notably, the builtin echo in sh(1) does not
     accept the -n option.  Consult the builtin(1) manual page.


Regards,
Steve.

```

## Shawn O. Pearce, 2008-10-31 14:32

Subject: Re: [PATCH] Avoid using non-portable `echo -n` in tests.
Message-ID: <20081031143200.GR14786@spearce.org>
URL: https://gitlist.dev/e/20081031143200.GR14786%40spearce.org
In-Reply-To: <1225429753-70109-1-git-send-email-benji@silverinsanity.com>

```
Brian Gernhardt <benji@silverinsanity.com> wrote:
> Not all /bin/sh have a builtin echo that recognizes -n.  Using printf
> is far more portable.
 
> diff --git a/t/t9400-git-cvsserver-server.sh b/t/t9400-git-cvsserver-server.sh
> index c1850d2..f6a2dbd 100755
> --- a/t/t9400-git-cvsserver-server.sh
> +++ b/t/t9400-git-cvsserver-server.sh
> @@ -424,7 +424,7 @@ cd "$WORKDIR"
>  test_expect_success 'cvs update (-p)' '
>      touch really-empty &&
>      echo Line 1 > no-lf &&
> -    echo -n Line 2 >> no-lf &&
> +    printf Line 2 >> no-lf &&

That needs to be:

	printf 'Line 2'

to have the same result.  Fortunately I don't think it matters
in this test, but it does read odd.

-- 
Shawn.

```

## Brian Gernhardt, 2008-10-31 15:38

Subject: Re: [PATCH] Avoid using non-portable `echo -n` in tests.
Message-ID: <B8E9E11A-48B9-44A8-8ED2-812FFFCFABA6@silverinsanity.com>
URL: https://gitlist.dev/e/B8E9E11A-48B9-44A8-8ED2-812FFFCFABA6%40silverinsanity.com
In-Reply-To: <7vy70589jc.fsf@gitster.siamese.dyndns.org>

```

On Oct 31, 2008, at 4:15 AM, Junio C Hamano wrote:

> Brian Gernhardt <benji@silverinsanity.com> writes:
>
>> Not all /bin/sh have a builtin echo that recognizes -n.  Using printf
>> is far more portable.
>
> This is much better (minor nit: we do not care if echo is built-in or
> /bin/echo); the point of t4030 is to produce an incomplete line ;-).

Well, yes.  The reason I phrased it that way was that my /bin/echo  
recognizes -n but /bin/sh does not.

~~ Brian

```

## Jeff King, 2008-10-31 18:24

Subject: Re: [PATCH] Avoid using non-portable `echo -n` in tests.
Message-ID: <20081031182456.GC3230@sigill.intra.peff.net>
URL: https://gitlist.dev/e/20081031182456.GC3230%40sigill.intra.peff.net
In-Reply-To: <1225429753-70109-1-git-send-email-benji@silverinsanity.com>

```
On Fri, Oct 31, 2008 at 01:09:13AM -0400, Brian Gernhardt wrote:

> Not all /bin/sh have a builtin echo that recognizes -n.  Using printf
> is far more portable.
> 
> Discovered on OS X 10.5.5 in t4030-diff-textconv.sh and changed in all
> the test scripts.

Hmph. I think this is a good patch, and there is precedent in the past
(20fa04ea, 2aad957, 9754563). But I am surprised this was not caught by
our recent autobuilding project.

However, it seems to work on FreeBSD (which makes it doubly weird that
it is broken on OS X). On Solaris, the /bin/sh is so horribly broken
that I have to use bash anyway. Commit 9754563 claims breakage on AIX,
but it looks like Mike is doing the AIX builds with bash.

So I guess we just need an OS X autobuild. ;)

>  t/t4030-diff-textconv.sh           |    2 +-

And of course this one was me, but I blame JSixt, whose test I just
mindlessly copied. ;)

-Peff

```

## Pierre Habouzit, 2008-10-31 18:36

Subject: Re: [PATCH] Avoid using non-portable `echo -n` in tests.
Message-ID: <20081031183601.GB8464@artemis.corp>
URL: https://gitlist.dev/e/20081031183601.GB8464%40artemis.corp
In-Reply-To: <20081031182456.GC3230@sigill.intra.peff.net>

```
On Fri, Oct 31, 2008 at 06:24:56PM +0000, Jeff King wrote:
> On Fri, Oct 31, 2008 at 01:09:13AM -0400, Brian Gernhardt wrote:
> 
> > Not all /bin/sh have a builtin echo that recognizes -n.  Using printf
> > is far more portable.
> > 
> > Discovered on OS X 10.5.5 in t4030-diff-textconv.sh and changed in all
> > the test scripts.
> 
> Hmph. I think this is a good patch, and there is precedent in the past
> (20fa04ea, 2aad957, 9754563). But I am surprised this was not caught by
> our recent autobuilding project.

Set up a Debian autobuilder with dash as a /bin/sh (apt-get install
dash, dpkg-reconfigure -plow dash and say 'yes'). You'll see those kind
of problems arise immediately.

Dash is a POSIX compatible shell, with almost no extension added (in
particular its echo has no -n option) which helps to find those kind of
issues.

It would help detecting git shell scripts that use bashism as well.

-- 
·O·  Pierre Habouzit
··O                                                madcoder@debian.org
OOO                                                http://www.madism.org

```

## Jeff King, 2008-10-31 18:39

Subject: Re: [PATCH] Avoid using non-portable `echo -n` in tests.
Message-ID: <20081031183933.GA3577@sigill.intra.peff.net>
URL: https://gitlist.dev/e/20081031183933.GA3577%40sigill.intra.peff.net
In-Reply-To: <20081031183601.GB8464@artemis.corp>

```
On Fri, Oct 31, 2008 at 07:36:01PM +0100, Pierre Habouzit wrote:

> Set up a Debian autobuilder with dash as a /bin/sh (apt-get install
> dash, dpkg-reconfigure -plow dash and say 'yes'). You'll see those kind
> of problems arise immediately.

I don't need to; my development box is Debian with dash as /bin/sh. :)

> Dash is a POSIX compatible shell, with almost no extension added (in
> particular its echo has no -n option) which helps to find those kind of
> issues.
> 
> It would help detecting git shell scripts that use bashism as well.

Agreed, and actually I found such a bashism (test ==) last week (though
of course it also broke on FreeBSD).

-Peff

```

## Francis Galiegue, 2008-10-31 19:35

Subject: Re: [PATCH] Avoid using non-portable `echo -n` in tests.
Message-ID: <200810312035.20016.fg@one2team.com>
URL: https://gitlist.dev/e/200810312035.20016.fg%40one2team.com
In-Reply-To: <20081031183933.GA3577@sigill.intra.peff.net>

```
Le Friday 31 October 2008 19:39:33 Jeff King, vous avez écrit :
[...]
>
> Agreed, and actually I found such a bashism (test ==) last week (though
> of course it also broke on FreeBSD).
>

As for bash-isms, a hunt for $(...) also looks necessary...

$ grep -rl '\$([^)]\+)' $(find -type f)|wc -l
272

Unless I'm mistaken (and I probably am), the $(...) construct is 
bash-specific, isn't it?

-- 
Francis Galiegue
ONE2TEAM
Ingénieur système
Mob : +33 (0) 6 83 87 78 75
Tel : +33 (0) 1 78 94 55 52
fge@one2team.com
40 avenue Raymond Poincaré
75116 Paris

```

## Johannes Schindelin, 2008-10-31 22:53

Subject: Re: [PATCH] Avoid using non-portable `echo -n` in tests.
Message-ID: <alpine.DEB.1.00.0810312352120.22125@pacific.mpi-cbg.de.mpi-cbg.de>
URL: https://gitlist.dev/e/alpine.DEB.1.00.0810312352120.22125%40pacific.mpi-cbg.de.mpi-cbg.de
In-Reply-To: <200810312035.20016.fg@one2team.com>

```
Hi,

On Fri, 31 Oct 2008, Francis Galiegue wrote:

> Unless I'm mistaken (and I probably am), the $(...) construct is 
> bash-specific, isn't it?

You're mistaken,
Dscho

P.S.: 
http://www.opengroup.org/onlinepubs/000095399/utilities/xcu_chap02.html#tag_02_06_03

```

## Mike Ralphson, 2008-11-03 16:30

Subject: Re: [PATCH] Avoid using non-portable `echo -n` in tests.
Message-ID: <e2b179460811030830t429a469bs3200fade42fecc01@mail.gmail.com>
URL: https://gitlist.dev/e/e2b179460811030830t429a469bs3200fade42fecc01%40mail.gmail.com
In-Reply-To: <20081031182456.GC3230@sigill.intra.peff.net>

```
2008/10/31 Jeff King <peff@peff.net>:
> On Fri, Oct 31, 2008 at 01:09:13AM -0400, Brian Gernhardt wrote:
>
>> Not all /bin/sh have a builtin echo that recognizes -n.  Using printf
>> is far more portable.
>>
>> Discovered on OS X 10.5.5 in t4030-diff-textconv.sh and changed in all
>> the test scripts.
>
> Hmph. I think this is a good patch, and there is precedent in the past
> (20fa04ea, 2aad957, 9754563). But I am surprised this was not caught by
> our recent autobuilding project.
>
> However, it seems to work on FreeBSD (which makes it doubly weird that
> it is broken on OS X). On Solaris, the /bin/sh is so horribly broken
> that I have to use bash anyway. Commit 9754563 claims breakage on AIX,
> but it looks like Mike is doing the AIX builds with bash.

I've just retested with AIX's standard sh (ksh) instead of bash and
there were only two issues.

Oddly enough, one was with the (original) printfs in
t4030-diff-textconv.sh. AIX seems to ship with a perfectly good
printf, but if you install the GNU tools from the 'IBM toolbox for
AIX' (and prepend them to your PATH) it replaces that printf with one
which doesn't grok the "\\1\\n" syntax, but I think wants it to be
"\\01\\n".

The other problem is the 'trap exit' one discussed here:
http://thread.gmane.org/gmane.comp.version-control.git/92748/focus=92944

Mike

```
