Re: [RFC] war on echo in scripts

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

Re: [RFC] war on echo in scripts

From: Andreas Schwab <hidden>
Date: 2016-06-15 22:49:06

Jonathan Nieder [off-list ref] writes:
quoted hunk
diff --git a/contrib/examples/git-clone.sh b/contrib/examples/git-clone.sh
index 547228e..e85ccda 100755
--- a/contrib/examples/git-clone.sh
+++ b/contrib/examples/git-clone.sh
@@ -28,7 +28,7 @@ use-separate-remote  compatibility, do not use
 no-separate-remote   compatibility, do not use"
 
 die() {
-	echo >&2 "$@"
+	printf >&2 '%s\n' "$@"
You probably want to use "$*" here, though it wouldn't matter for the
uses of die in this file.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

Re: [RFC] war on echo in scripts

From: Jonathan Nieder <hidden>
Date: 2016-06-15 22:49:06

Andreas Schwab wrote:
Jonathan Nieder [off-list ref] writes:
quoted
 die() {
-	echo >&2 "$@"
+	printf >&2 '%s\n' "$@"
You probably want to use "$*" here, though it wouldn't matter for the
uses of die in this file.
Hmm, maybe something like this would be easier.

Signed-off-by: Jonathan Nieder <redacted>
---
diff --git a/git-sh-setup.sh b/git-sh-setup.sh
index 6131670..b38b40b 100644
--- a/git-sh-setup.sh
+++ b/git-sh-setup.sh
@@ -39,6 +39,10 @@ git_broken_path_fix () {
 
 # @@BROKEN_PATH_FIX@@
 
+echo() {
+	printf '%s\n' "$*"
+}
+
 die() {
 	echo >&2 "$@"
 	exit 1
-- 

Re: [RFC] war on echo in scripts

From: Sverre Rabbelier <hidden>
Date: 2016-06-15 22:49:06

Heya,

On Thu, Jul 8, 2010 at 21:46, Jonathan Nieder [off-list ref] wrote:
Hmm, maybe something like this would be easier.
You mean instead of the fairly huge patch you sent earlier? Sounds
like a good deal to me ;).

-- 
Cheers,

Sverre Rabbelier

Re: [RFC] war on echo in scripts

From: Ævar Arnfjörð Bjarmason <hidden>
Date: 2016-06-15 22:49:06

On Fri, Jul 9, 2010 at 02:46, Jonathan Nieder [off-list ref] wrote:
Andreas Schwab wrote:
quoted
Jonathan Nieder [off-list ref] writes:
quoted
quoted
 die() {
-    echo >&2 "$@"
+    printf >&2 '%s\n' "$@"
You probably want to use "$*" here, though it wouldn't matter for the
uses of die in this file.
Hmm, maybe something like this would be easier.
[...]
+echo() {
+       printf '%s\n' "$*"
+}
+
Overriding builtins like this isn't portable.

(Via H.Merijn Brand): This fails on the old HP-UX 10.20 bourne shell:

    > cat xx.sh
    #!/bin/sh

    echo ()
    {
    perl -le'print "Done!"'
    }

    echo 1
    echo Klaar
    > sh xx.sh
    xx.sh[3]: The operation is not allowed in a restricted shell.:
echo is a shell builtin.
    1
    Klaar

Re: [RFC] war on echo in scripts

From: Jonathan Nieder <hidden>
Date: 2016-06-15 22:49:06

Ævar Arnfjörð Bjarmason wrote:
(Via H.Merijn Brand): This fails on the old HP-UX 10.20 bourne shell:
Git commands require a Posix-style shell (with support for $() among
other things), which I suspect would rule out shells like the one
you’re talking about.  Still, portability is something to worry
about...
    > cat xx.sh
    #!/bin/sh

    echo ()
    {
    perl -le'print "Done!"'
    }

    echo 1
    echo Klaar
    > sh xx.sh
    xx.sh[3]: The operation is not allowed in a restricted shell.:
echo is a shell builtin.
    1
    Klaar
That’s weird.  Where did “restricted shell” come into it?

Thanks for the example,
Jonathan
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help