timezone: re-written tzselect as posix sh

Message ID 20211202070658.2164977-3-raj.khem@gmail.com
State Dropped
Headers
Series timezone: re-written tzselect as posix sh |

Checks

Context Check Description
dj/TryBot-apply_patch success Patch applied to master at the time it was sent
dj/TryBot-32bit success Build for i686

Commit Message

Khem Raj Dec. 2, 2021, 7:06 a.m. UTC
  To avoid the bash dependency.

Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
Signed-off-by: Khem Raj <raj.khem@gmail.com>
---
 timezone/tzselect.ksh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
  

Comments

Florian Weimer Dec. 2, 2021, 3:38 p.m. UTC | #1
* Khem Raj via Libc-alpha:

> To avoid the bash dependency.
>
> Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
> Signed-off-by: Khem Raj <raj.khem@gmail.com>
> ---
>  timezone/tzselect.ksh | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/timezone/tzselect.ksh b/timezone/tzselect.ksh
> index 18fce27e24..7705df83d7 100755
> --- a/timezone/tzselect.ksh
> +++ b/timezone/tzselect.ksh
> @@ -1,4 +1,4 @@
> -#!/bin/bash
> +#!/bin/sh
>  # Ask the user about the time zone, and output the resulting TZ value to stdout.
>  # Interact with the user via stderr and stdin.
>  
> @@ -34,7 +34,7 @@ REPORT_BUGS_TO=tz@iana.org
>  
>  # Specify default values for environment variables if they are unset.
>  : ${AWK=awk}
> -: ${TZDIR=`pwd`}
> +: ${TZDIR=$(pwd)}
>  
>  # Output one argument as-is to standard output.
>  # Safer than 'echo', which can mishandle '\' or leading '-'.

Is this really a bashism?  I'm surprised.

Thanks,
Florian
  
Khem Raj Dec. 2, 2021, 4:15 p.m. UTC | #2
On Thu, Dec 2, 2021 at 7:38 AM Florian Weimer <fweimer@redhat.com> wrote:
>
> * Khem Raj via Libc-alpha:
>
> > To avoid the bash dependency.
> >
> > Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
> > Signed-off-by: Khem Raj <raj.khem@gmail.com>
> > ---
> >  timezone/tzselect.ksh | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/timezone/tzselect.ksh b/timezone/tzselect.ksh
> > index 18fce27e24..7705df83d7 100755
> > --- a/timezone/tzselect.ksh
> > +++ b/timezone/tzselect.ksh
> > @@ -1,4 +1,4 @@
> > -#!/bin/bash
> > +#!/bin/sh
> >  # Ask the user about the time zone, and output the resulting TZ value to stdout.
> >  # Interact with the user via stderr and stdin.
> >
> > @@ -34,7 +34,7 @@ REPORT_BUGS_TO=tz@iana.org
> >
> >  # Specify default values for environment variables if they are unset.
> >  : ${AWK=awk}
> > -: ${TZDIR=`pwd`}
> > +: ${TZDIR=$(pwd)}
> >
> >  # Output one argument as-is to standard output.
> >  # Safer than 'echo', which can mishandle '\' or leading '-'.
>
> Is this really a bashism?  I'm surprised.

you are right. I tested it on bash/dash/zsh/ash it works as expected.
Let me find
the real reason for this patch and come back.

>
> Thanks,
> Florian
>
  
Joseph Myers Dec. 2, 2021, 6:55 p.m. UTC | #3
tzselect.ksh is supposed to be taken verbatim from upstream tzcode, not 
locally modified.  See timezone/README.
  
Paul Eggert Dec. 2, 2021, 9:30 p.m. UTC | #4
On 12/1/21 23:06, Khem Raj via Libc-alpha wrote:
> To avoid the bash dependency.

A better way to avoid any Bash dependency would be to change 
timezone/Makefile's $(objpfx)tzselect rule to add a line like this:

    -e 's|#!/bin/bash|#!$(KSHELL)|g' \

where KSHELL is suitably defined for your platform. This is what the 
upstream (tzcode) Makefile does, and doing it this way would mean that 
tzselect.ksh could stay identical with upstream.

For KSHELL it's better to use Bash or some other Korn-compatible shell 
if available, since tzselect takes advantage of ksh-style 'select' 
commands (when the shell supports 'select') to have a somewhat better UI.


> -: ${TZDIR=`pwd`}
> +: ${TZDIR=$(pwd)}

This part of the patch is not relevant to any Bash dependency, since the 
form with `` should be supported by any POSIX shell.

That being said, nowadays tzselect.ksh could be streamlined a bit since 
we no longer need to worry about compatibility with Solaris 9 sh. I'll 
try to kick free some time to do that upstream.
  

Patch

diff --git a/timezone/tzselect.ksh b/timezone/tzselect.ksh
index 18fce27e24..7705df83d7 100755
--- a/timezone/tzselect.ksh
+++ b/timezone/tzselect.ksh
@@ -1,4 +1,4 @@ 
-#!/bin/bash
+#!/bin/sh
 # Ask the user about the time zone, and output the resulting TZ value to stdout.
 # Interact with the user via stderr and stdin.
 
@@ -34,7 +34,7 @@  REPORT_BUGS_TO=tz@iana.org
 
 # Specify default values for environment variables if they are unset.
 : ${AWK=awk}
-: ${TZDIR=`pwd`}
+: ${TZDIR=$(pwd)}
 
 # Output one argument as-is to standard output.
 # Safer than 'echo', which can mishandle '\' or leading '-'.