git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] Avoid using `echo -n` anywhere

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 29, 2013, 17:07 UTC
Message-ID
<7vr4ehz44w.fsf@alter.siamese.dyndns.org>
In-Reply-To
<1374927093-16663-1-git-send-email-git@cryptocrack.de>
Lukas Fleischer <git@cryptocrack.de> writes:
Show 30 quoted lines
> `echo -n` is non-portable. The POSIX specification says:
>
>     Conforming applications that wish to do prompting without <newline>
>     characters or that could possibly be expecting to echo a -n, should
>     use the printf utility derived from the Ninth Edition system.
>
> Since all of the affected shell scripts use a POSIX shell shebang,
> replace `echo -n` invocations with printf.
>
> Signed-off-by: Lukas Fleischer <git@cryptocrack.de>
> ...
> diff --git a/t/perf/perf-lib.sh b/t/perf/perf-lib.sh
> index c61d535..ae44117 100644
> --- a/t/perf/perf-lib.sh
> +++ b/t/perf/perf-lib.sh
> @@ -161,7 +161,7 @@ test_perf () {
>  		echo "$test_count" >>"$perf_results_dir"/$base.subtests
>  		echo "$1" >"$perf_results_dir"/$base.$test_count.descr
>  		if test -z "$verbose"; then
> -			echo -n "perf $test_count - $1:"
> +			printf "%s" "perf $test_count - $1:"
>  		else
>  			echo "perf $test_count - $1:"
>  		fi
> @@ -170,7 +170,7 @@ test_perf () {
>  			if test_run_perf_ "$2"
>  			then
>  				if test -z "$verbose"; then
> -					echo -n " $i"
> +					printf " %d" "$i"

I'd prefer to see '%s' here; it is more faithful transliteration from "echo -n".

Thanks, will queue with the above tweak.
>  				else
>  					echo "* timing run $i/$GIT_PERF_REPEAT_COUNT:"
>  				fi
Previous: Lukas Fleischer
Message 3 of 3 in “subtree split prepends "-n<newline>" to commit messages on OS X”
  1. Bryan HeadJul 26, 2013
  2. Avoid using `echo -n` anywhereLukas Fleischer, Jul 27, 2013
  3. Junio C HamanoJul 29, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.