contrib: Avoid use of "echo -n" in git customization [PR102664]

Message ID fea9431c-e183-53a8-c883-1bfb31ecf1d2@foss.arm.com
State Superseded
Headers
Series contrib: Avoid use of "echo -n" in git customization [PR102664] |

Commit Message

Richard Earnshaw March 9, 2022, 12:15 p.m. UTC
  The -n option to echo is non-portable.  The generally recommended
alternative is to use the shell printf command.

contrib/ChangeLog:

	PR other/102664
	* gcc-git-customization.sh (ask): Use printf instead of echo -n.
  

Comments

Jonathan Wakely March 9, 2022, 3:05 p.m. UTC | #1
On 09/03/22 12:15 +0000, Richard Earnshaw wrote:
>The -n option to echo is non-portable.  The generally recommended
>alternative is to use the shell printf command.
>
>contrib/ChangeLog:
>
>	PR other/102664
>	* gcc-git-customization.sh (ask): Use printf instead of echo -n.
>
>diff --git a/contrib/gcc-git-customization.sh b/contrib/gcc-git-customization.sh
>index b24948d9874..cf46c494a6a 100755
>--- a/contrib/gcc-git-customization.sh
>+++ b/contrib/gcc-git-customization.sh
>@@ -7,7 +7,7 @@ ask () {
>     question=$1
>     default=$2
>     var=$3
>-    echo -n $question "["$default"]? "
>+    printf "%s" "$question [$default]? "
>     read answer
>     if [ "x$answer" = "x" ]
>     then

This isn't enough to get the script working on AIX and Solaris. The
attached patch has been tested on Fedora Linux, NetBSD 9.2, AIX 7 and
Solaris 11.

The part checking the result of `git rev-parse --git-path hooks` was
needed to work around Git 2.4.0 on gcc211 in the compile farm, which
is a Solaris 11 sparc box. That's a truly ancient version, but
handling the error (and just skipping installation of the hook) isn't
difficult, so seems worthwhile. I can revert that part if preferred.

OK for trunk?
  
Richard Earnshaw March 10, 2022, 11:43 a.m. UTC | #2
On 09/03/2022 15:05, Jonathan Wakely via Gcc-patches wrote:
> On 09/03/22 12:15 +0000, Richard Earnshaw wrote:
>> The -n option to echo is non-portable.  The generally recommended
>> alternative is to use the shell printf command.
>>
>> contrib/ChangeLog:
>>
>>     PR other/102664
>>     * gcc-git-customization.sh (ask): Use printf instead of echo -n.
>>
>> diff --git a/contrib/gcc-git-customization.sh 
>> b/contrib/gcc-git-customization.sh
>> index b24948d9874..cf46c494a6a 100755
>> --- a/contrib/gcc-git-customization.sh
>> +++ b/contrib/gcc-git-customization.sh
>> @@ -7,7 +7,7 @@ ask () {
>>     question=$1
>>     default=$2
>>     var=$3
>> -    echo -n $question "["$default"]? "
>> +    printf "%s" "$question [$default]? "
>>     read answer
>>     if [ "x$answer" = "x" ]
>>     then
> 
> This isn't enough to get the script working on AIX and Solaris. The
> attached patch has been tested on Fedora Linux, NetBSD 9.2, AIX 7 and
> Solaris 11.
> 
> The part checking the result of `git rev-parse --git-path hooks` was
> needed to work around Git 2.4.0 on gcc211 in the compile farm, which
> is a Solaris 11 sparc box. That's a truly ancient version, but
> handling the error (and just skipping installation of the hook) isn't
> difficult, so seems worthwhile. I can revert that part if preferred.
> 
> OK for trunk?
> 
> 

OK.
  

Patch

diff --git a/contrib/gcc-git-customization.sh b/contrib/gcc-git-customization.sh
index b24948d9874..cf46c494a6a 100755
--- a/contrib/gcc-git-customization.sh
+++ b/contrib/gcc-git-customization.sh
@@ -7,7 +7,7 @@  ask () {
     question=$1
     default=$2
     var=$3
-    echo -n $question "["$default"]? "
+    printf "%s" "$question [$default]? "
     read answer
     if [ "x$answer" = "x" ]
     then