{"thread":{"id":"6394","subject":"[PATCH] Replace \"echo -n\" with printf in shell scripts.","startedAt":"2007-01-16T01:31:29Z","lastAt":"2007-01-18T00:13:43Z","messageCount":11,"participants":["Jason Riedy","Junio C Hamano","Eric Blake","Horst H. von Brand","Brian Gernhardt","Julian Phillips","Simon 'corecode' Schubert"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"31790","messageId":"17437.1168911089@lotus.CS.Berkeley.EDU","threadId":"6394","inReplyTo":null,"subject":"[PATCH] Replace \"echo -n\" with printf in shell scripts.","fromName":"Jason Riedy","fromEmail":"ejr@eecs.berkeley.edu","sentAt":"2007-01-16T01:31:29Z","receivedAt":"2007-01-16T01:31:29Z","isPatch":true,"sender":{"key":"ejr@eecs.berkeley.edu","avatar":"https://gravatar.com/avatar/547fa56f887cab01599edab4e9f813c949c1269e02714f20e0496c56185d9837?d=mp&s=160"},"body":"Not all echos know -n.  This was causing a test failure in\nt5401-update-hooks.sh, but not t3800-mktag.sh for some reason.\n\nSigned-off-by: Jason Riedy <ejr@cs.berkeley.edu>\n---\n contrib/remotes2config.sh |    2 +-\n git-quiltimport.sh        |    2 +-\n git-reset.sh              |    2 +-\n t/t3800-mktag.sh          |    2 +-\n t/t5401-update-hooks.sh   |    4 ++--\n t/t6023-merge-file.sh     |    2 +-\n 6 files changed, 7 insertions(+), 7 deletions(-)\n\ndiff --git a/contrib/remotes2config.sh b/contrib/remotes2config.sh\nindex 25901e2..b996996 100644\n--- a/contrib/remotes2config.sh\n+++ b/contrib/remotes2config.sh\n@@ -11,7 +11,7 @@ if [ -d \"$GIT_DIR\"/remotes ]; then\n \t{\n \t\tcd \"$GIT_DIR\"/remotes\n \t\tls | while read f; do\n-\t\t\tname=$(echo -n \"$f\" | tr -c \"A-Za-z0-9\" \".\")\n+\t\t\tname=$(printf \"$f\" | tr -c \"A-Za-z0-9\" \".\")\n \t\t\tsed -n \\\n \t\t\t-e \"s/^URL: \\(.*\\)$/remote.$name.url \\1 ./p\" \\\n \t\t\t-e \"s/^Pull: \\(.*\\)$/remote.$name.fetch \\1 ^$ /p\" \\\ndiff --git a/git-quiltimport.sh b/git-quiltimport.sh\nindex 10135da..2ae1f20 100755\n--- a/git-quiltimport.sh\n+++ b/git-quiltimport.sh\n@@ -89,7 +89,7 @@ for patch_name in $(cat \"$QUILT_PATCHES/series\" | grep -v '^#'); do\n \t\t\techo \"No author found in $patch_name\" >&2;\n \t\t\techo \"---\"\n \t\t\tcat $tmp_msg\n-\t\t\techo -n \"Author: \";\n+\t\t\tprintf \"Author: \";\n \t\t\tread patch_author\n \n \t\t\techo \"$patch_author\"\ndiff --git a/git-reset.sh b/git-reset.sh\nindex 91c7e6e..bf2a058 100755\n--- a/git-reset.sh\n+++ b/git-reset.sh\n@@ -87,7 +87,7 @@ update_ref_status=$?\n case \"$reset_type\" in\n --hard )\n \ttest $update_ref_status = 0 && {\n-\t\techo -n \"HEAD is now at \"\n+\t\tprintf \"HEAD is now at \"\n \t\tGIT_PAGER= git log --max-count=1 --pretty=oneline \\\n \t\t\t--abbrev-commit HEAD\n \t}\ndiff --git a/t/t3800-mktag.sh b/t/t3800-mktag.sh\nindex 5b23b77..ede4d42 100755\n--- a/t/t3800-mktag.sh\n+++ b/t/t3800-mktag.sh\n@@ -88,7 +88,7 @@ check_verify_failure '\"type\" line label check'\n #  5. type line eol check\n \n echo \"object 779e9b33986b1c2670fff52c5067603117b3e895\" >tag.sig\n-echo -n \"type tagsssssssssssssssssssssssssssssss\" >>tag.sig\n+printf \"type tagsssssssssssssssssssssssssssssss\" >>tag.sig\n \n cat >expect.pat <<EOF\n ^error: char48: .*\"[\\]n\"$\ndiff --git a/t/t5401-update-hooks.sh b/t/t5401-update-hooks.sh\nindex cd8cee6..0514056 100755\n--- a/t/t5401-update-hooks.sh\n+++ b/t/t5401-update-hooks.sh\n@@ -23,7 +23,7 @@ test_expect_success setup '\n cat >victim/.git/hooks/update <<'EOF'\n #!/bin/sh\n echo \"$@\" >$GIT_DIR/update.args\n-read x; echo -n \"$x\" >$GIT_DIR/update.stdin\n+read x; printf \"$x\" >$GIT_DIR/update.stdin\n echo STDOUT update\n echo STDERR update >&2\n EOF\n@@ -32,7 +32,7 @@ chmod u+x victim/.git/hooks/update\n cat >victim/.git/hooks/post-update <<'EOF'\n #!/bin/sh\n echo \"$@\" >$GIT_DIR/post-update.args\n-read x; echo -n \"$x\" >$GIT_DIR/post-update.stdin\n+read x; printf \"$x\" >$GIT_DIR/post-update.stdin\n echo STDOUT post-update\n echo STDERR post-update >&2\n EOF\ndiff --git a/t/t6023-merge-file.sh b/t/t6023-merge-file.sh\nindex 1c21d8c..f3cd3db 100644\n--- a/t/t6023-merge-file.sh\n+++ b/t/t6023-merge-file.sh\n@@ -52,7 +52,7 @@ super aquam refectionis educavit me;\n animam meam convertit,\n deduxit me super semitas jusitiae,\n EOF\n-echo -n \"propter nomen suum.\" >> new4.txt\n+printf \"propter nomen suum.\" >> new4.txt\n \n cp new1.txt test.txt\n test_expect_success \"merge without conflict\" \\\n-- \n1.5.0.rc1.gf4b6c\n"},{"id":"31794","messageId":"7v1wlv1yeh.fsf@assigned-by-dhcp.cox.net","threadId":"6394","inReplyTo":"17437.1168911089@lotus.CS.Berkeley.EDU","subject":"Re: [PATCH] Replace \"echo -n\" with printf in shell scripts.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2007-01-16T02:46:46Z","receivedAt":"2007-01-16T02:46:46Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jason Riedy <ejr@EECS.Berkeley.EDU> writes:\n\n> Not all echos know -n.  This was causing a test failure in\n> t5401-update-hooks.sh, but not t3800-mktag.sh for some reason.\n\nWe have done this already so it might be too late to raise this\nquestion, but does everybody have printf?\n\n> diff --git a/contrib/remotes2config.sh b/contrib/remotes2config.sh\n> index 25901e2..b996996 100644\n> --- a/contrib/remotes2config.sh\n> +++ b/contrib/remotes2config.sh\n> @@ -11,7 +11,7 @@ if [ -d \"$GIT_DIR\"/remotes ]; then\n>  \t{\n>  \t\tcd \"$GIT_DIR\"/remotes\n>  \t\tls | while read f; do\n> -\t\t\tname=$(echo -n \"$f\" | tr -c \"A-Za-z0-9\" \".\")\n> +\t\t\tname=$(printf \"$f\" | tr -c \"A-Za-z0-9\" \".\")\n\nThis should almost be safe as no sane person would have a remote\nwhose name is 'foo%s'...\n"},{"id":"31797","messageId":"18039.1168916633@lotus.CS.Berkeley.EDU","threadId":"6394","inReplyTo":"7v1wlv1yeh.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] Replace \"echo -n\" with printf in shell scripts.","fromName":"Jason Riedy","fromEmail":"ejr@cs.berkeley.edu","sentAt":"2007-01-16T03:03:53Z","receivedAt":"2007-01-16T03:03:53Z","isPatch":true,"sender":{"key":"ejr@eecs.berkeley.edu","avatar":"https://gravatar.com/avatar/547fa56f887cab01599edab4e9f813c949c1269e02714f20e0496c56185d9837?d=mp&s=160"},"body":"And Junio C Hamano writes:\n> We have done this already so it might be too late to raise this\n> question, but does everybody have printf?\n\nIt's in the Single Unix Spec as the alternative to non-portable\necho uses:\n  http://opengroup.org/onlinepubs/007908799/xcu/echo.html#tag_001_014_525\nAnd no one has complained so far...\n\n> > -\t\t\tname=$(echo -n \"$f\" | tr -c \"A-Za-z0-9\" \".\")\n> > +\t\t\tname=$(printf \"$f\" | tr -c \"A-Za-z0-9\" \".\")\n\n> This should almost be safe as no sane person would have a remote\n> whose name is 'foo%s'...\n\nForgot about that, thanks.  It should be printf \"%s\" \"$f\".\n\nJason\n"},{"id":"31798","messageId":"45AC41F0.8090106@byu.net","threadId":"6394","inReplyTo":"7v1wlv1yeh.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] Replace \"echo -n\" with printf in shell scripts.","fromName":"Eric Blake","fromEmail":"ebb9@byu.net","sentAt":"2007-01-16T03:09:36Z","receivedAt":"2007-01-16T03:09:36Z","isPatch":true,"sender":{"key":"eblake@redhat.com","avatar":"https://avatars.githubusercontent.com/u/32933908?v=4"},"body":"-----BEGIN PGP SIGNED MESSAGE-----\nHash: SHA1\n\nAccording to Junio C Hamano on 1/15/2007 7:46 PM:\n>> -\t\t\tname=$(echo -n \"$f\" | tr -c \"A-Za-z0-9\" \".\")\n>> +\t\t\tname=$(printf \"$f\" | tr -c \"A-Za-z0-9\" \".\")\n> \n> This should almost be safe as no sane person would have a remote\n> whose name is 'foo%s'...\n\nWhy not go all the way, and make it safe, regardless of embedded %,\nembedded \\, or leading -?\n\nname=$(printf -- %s \"$f\" | tr -c \"A-Za-z0-9\" \".\")\n\n- --\nDon't work too hard, make some time for fun as well!\n\nEric Blake             ebb9@byu.net\n-----BEGIN PGP SIGNATURE-----\nVersion: GnuPG v1.4.5 (Cygwin)\nComment: Public key at home.comcast.net/~ericblake/eblake.gpg\nComment: Using GnuPG with Mozilla - http://enigmail.mozdev.org\n\niD8DBQFFrEHw84KuGfSFAYARAlH9AJ9q3atCpSVBTg0SVhZ4DQ9T7qiqEQCfe9D2\nbGTfwnvW6uN1ky6ncWYgkgc=\n=P9t5\n-----END PGP SIGNATURE-----\n"},{"id":"31894","messageId":"200701171629.l0HGTCE3019292@laptop13.inf.utfsm.cl","threadId":"6394","inReplyTo":"7v1wlv1yeh.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] Replace \"echo -n\" with printf in shell scripts.","fromName":"Horst H. von Brand","fromEmail":"vonbrand@inf.utfsm.cl","sentAt":"2007-01-17T16:29:12Z","receivedAt":"2007-01-17T16:29:12Z","isPatch":true,"sender":{"key":"vonbrand@inf.utfsm.cl","avatar":"https://avatars.githubusercontent.com/u/211384?v=4"},"body":"Junio C Hamano <junkio@cox.net> wrote:\n> Jason Riedy <ejr@EECS.Berkeley.EDU> writes:\n> > Not all echos know -n.  This was causing a test failure in\n> > t5401-update-hooks.sh, but not t3800-mktag.sh for some reason.\n> \n> We have done this already so it might be too late to raise this\n> question, but does everybody have printf?\n\nHere (Fedora rawhide) /usr/bin/printf is part of coreutils.\n-- \nDr. Horst H. von Brand                   User #22616 counter.li.org\nDepartamento de Informatica                    Fono: +56 32 2654431\nUniversidad Tecnica Federico Santa Maria             +56 32 2654239\nCasilla 110-V, Valparaiso, Chile               Fax:  +56 32 2797513\n"},{"id":"31901","messageId":"7vk5zlsglk.fsf@assigned-by-dhcp.cox.net","threadId":"6394","inReplyTo":"200701171629.l0HGTCE3019292@laptop13.inf.utfsm.cl","subject":"Re: [PATCH] Replace \"echo -n\" with printf in shell scripts.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2007-01-17T17:33:43Z","receivedAt":"2007-01-17T17:33:43Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Horst H. von Brand\" <vonbrand@inf.utfsm.cl> writes:\n\n> Junio C Hamano <junkio@cox.net> wrote:\n>> Jason Riedy <ejr@EECS.Berkeley.EDU> writes:\n>> > Not all echos know -n.  This was causing a test failure in\n>> > t5401-update-hooks.sh, but not t3800-mktag.sh for some reason.\n>> \n>> We have done this already so it might be too late to raise this\n>> question, but does everybody have printf?\n>\n> Here (Fedora rawhide) /usr/bin/printf is part of coreutils.\n\nI am reasonably sure people on Linux land would be fine\nregardless of distros, but thanks anyway.\n\nThe problematic are less common ones, ranging from (not so less\ncommon) OSX, Solaris to (much less common) AIX that some people\nseem to run git on (or at least compile git for).\n"},{"id":"31902","messageId":"F850C6F1-EFDC-4D37-90B4-27D8982BA086@silverinsanity.com","threadId":"6394","inReplyTo":"7vk5zlsglk.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] Replace \"echo -n\" with printf in shell scripts.","fromName":"Brian Gernhardt","fromEmail":"benji@silverinsanity.com","sentAt":"2007-01-17T18:00:31Z","receivedAt":"2007-01-17T18:00:31Z","isPatch":true,"sender":{"key":"benji@silverinsanity.com","avatar":"https://gravatar.com/avatar/e06c101dbc25c68114d859b4a9ec7cf8a2c52fd2b0270ef0eac0e2e63ff22311?d=mp&s=160"},"body":"\nOn Jan 17, 2007, at 12:33 PM, Junio C Hamano wrote:\n\n> The problematic are less common ones, ranging from (not so less\n> common) OSX, Solaris to (much less common) AIX that some people\n> seem to run git on (or at least compile git for).\n\nAt least as far a OS X goes, it's installed on my machine (10.4.8)  \nas /usr/bin/printf.  I don't know if it's part of the Xcode packages,  \nthe \"BSD Subsystem\", or the core OS but I have a hard time imagining  \nsomeone who didn't have them all installed using GIT.\n\nAlso, it's man page identifies itself as\n\"PRINTF(1)                 BSD General Commands Manual                 \nPRINTF(1)\"\nso most, if not all, flavors of BSD and BSD-like should be alright.\n\n~~ Brian\n"},{"id":"31904","messageId":"Pine.LNX.4.64.0701171804260.26185@reaper.quantumfyre.co.uk","threadId":"6394","inReplyTo":"7vk5zlsglk.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] Replace \"echo -n\" with printf in shell scripts.","fromName":"Julian Phillips","fromEmail":"julian@quantumfyre.co.uk","sentAt":"2007-01-17T18:07:20Z","receivedAt":"2007-01-17T18:07:20Z","isPatch":true,"sender":{"key":"julian@quantumfyre.co.uk","avatar":"https://avatars.githubusercontent.com/u/948888?v=4"},"body":"On Wed, 17 Jan 2007, Junio C Hamano wrote:\n\n> \"Horst H. von Brand\" <vonbrand@inf.utfsm.cl> writes:\n>\n>> Junio C Hamano <junkio@cox.net> wrote:\n>>> Jason Riedy <ejr@EECS.Berkeley.EDU> writes:\n>>>> Not all echos know -n.  This was causing a test failure in\n>>>> t5401-update-hooks.sh, but not t3800-mktag.sh for some reason.\n>>>\n>>> We have done this already so it might be too late to raise this\n>>> question, but does everybody have printf?\n>>\n>> Here (Fedora rawhide) /usr/bin/printf is part of coreutils.\n>\n> I am reasonably sure people on Linux land would be fine\n> regardless of distros, but thanks anyway.\n>\n> The problematic are less common ones, ranging from (not so less\n> common) OSX, Solaris to (much less common) AIX that some people\n> seem to run git on (or at least compile git for).\n\nprintf is a bash builtin ... not sure about other shells.\n\n-- \nJulian\n\n  ---\nA lifetime isn't nearly long enough to figure out what it's all about.\n"},{"id":"31918","messageId":"200701172017.l0HKHIA8032440@laptop13.inf.utfsm.cl","threadId":"6394","inReplyTo":"Pine.LNX.4.64.0701171804260.26185@reaper.quantumfyre.co.uk","subject":"Re: [PATCH] Replace \"echo -n\" with printf in shell scripts.","fromName":"Horst H. von Brand","fromEmail":"vonbrand@inf.utfsm.cl","sentAt":"2007-01-17T20:17:18Z","receivedAt":"2007-01-17T20:17:18Z","isPatch":true,"sender":{"key":"vonbrand@inf.utfsm.cl","avatar":"https://avatars.githubusercontent.com/u/211384?v=4"},"body":"Julian Phillips <julian@quantumfyre.co.uk> wrote:\n\n[...]\n\n> printf is a bash builtin ... not sure about other shells.\n\nIt's a builtin in zsh and in ksh, and /not/ in tcsh here (Fedora rawhide)\n\nzsh-4.2.6-3.fc7\nksh-20060214-1.1\ntcsh-6.14-13\n\nIt might be special configuration, but as they are mentioned in the manpages\nI'd guess not.\n-- \nDr. Horst H. von Brand                   User #22616 counter.li.org\nDepartamento de Informatica                    Fono: +56 32 2654431\nUniversidad Tecnica Federico Santa Maria             +56 32 2654239\nCasilla 110-V, Valparaiso, Chile               Fax:  +56 32 2797513\n"},{"id":"31931","messageId":"45AEB932.3060509@fs.ei.tum.de","threadId":"6394","inReplyTo":"7vk5zlsglk.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] Replace \"echo -n\" with printf in shell scripts.","fromName":"Simon 'corecode' Schubert","fromEmail":"corecode@fs.ei.tum.de","sentAt":"2007-01-18T00:02:58Z","receivedAt":"2007-01-18T00:02:58Z","isPatch":true,"sender":{"key":"corecode@fs.ei.tum.de","avatar":"https://gravatar.com/avatar/eff9dbf0cdac0d1e6a6cd7ed0e50763edcb376b493b5253a35ff167918ad79e1?d=mp&s=160"},"body":"Junio C Hamano wrote:\n>>> We have done this already so it might be too late to raise this\n>>> question, but does everybody have printf?\n> The problematic are less common ones, ranging from (not so less\n> common) OSX, Solaris to (much less common) AIX that some people\n> seem to run git on (or at least compile git for).\n\nprintf(1) is part of POSIX/SUSv3, so systems *should* have it.\n\ncheers\n  simon\n\n-- \nServe - BSD     +++  RENT this banner advert  +++    ASCII Ribbon   /\"\\\nWork - Mac      +++  space for low €€€ NOW!1  +++      Campaign     \\ /\nParty Enjoy Relax   |   http://dragonflybsd.org      Against  HTML   \\\nDude 2c 2 the max   !   http://golden-apple.biz       Mail + News   / \\\n\n"},{"id":"31930","messageId":"7v7ivlp4y0.fsf@assigned-by-dhcp.cox.net","threadId":"6394","inReplyTo":"45AEB932.3060509@fs.ei.tum.de","subject":"Re: [PATCH] Replace \"echo -n\" with printf in shell scripts.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2007-01-18T00:13:43Z","receivedAt":"2007-01-18T00:13:43Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Simon 'corecode' Schubert <corecode@fs.ei.tum.de> writes:\n\n> Junio C Hamano wrote:\n>>>> We have done this already so it might be too late to raise this\n>>>> question, but does everybody have printf?\n>> The problematic are less common ones, ranging from (not so less\n>> common) OSX, Solaris to (much less common) AIX that some people\n>> seem to run git on (or at least compile git for).\n>\n> printf(1) is part of POSIX/SUSv3, so systems *should* have it.\n\nA lot of the portability problem we suffered were about the\nthings that systems *should* have it.\n\nUnfortunately a standard does not matter a whit on its own when\ndealing with the real world.  That's why I muttered the above\neven though I knew POSIX says you should have one.\n\nWe use POSIX as one of the yardsticks to see what we should stay\naway (i.e. \"that is not even in POSIX so let's not use it for\nnow\"), and also how far we are willing to bend over (i.e. \"any\nreasonable system should have it; besides, it is in POSIX.\nLet's use it -- it is so convenient -- and insane platforms can\nscrew themselves\").\n\nThe key point in the latter is that \"besides\" is not \"because\".\n"}]}