Uploaded image for project: 'RHEL'
  1. RHEL
  2. RHEL-5662

`bash -t` does not work on RHEL8.

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: Undefined Undefined
    • None
    • rhel-8.8.0
    • bash
    • None
    • Moderate
    • rhel-sst-cs-plumbers
    • ssg_core_services
    • None
    • False
    • Hide

      None

      Show
      None
    • None
    • None
    • None
    • None
    • If docs needed, set a value
    • None

      Description of problem:

      `bash -t` does not work on RHEL8.
      It works on RHEL7 and earlier, and on RHEL9.

      [root@rhel87 ~]# rpm -q bash
      bash-4.4.20-4.el8_6.x86_64
      [root@rhel87 ~]# bash -t <<< "echo hello"
      [root@rhel87 ~]#

      [root@rhel79 ~]# rpm -q bash
      bash-4.2.46-34.el7.x86_64
      [root@rhel79 ~]# bash -t <<< "echo hello"
      hello
      [root@rhel79 ~]#

      [root@rhel92 ~]# rpm -q bash
      bash-5.1.8-6.el9_1.x86_64
      [root@rhel92 ~]# bash -t <<< "echo hello"
      hello
      [root@rhel92 ~]#

      Version-Release number of selected component (if applicable):

      • Red Hat Enterprise Linux 8
      • bash-4.4.20-4.el8_6

      How reproducible:

      Always

      Steps to Reproduce:
      1. Run `bash -t <<< "echo hello"`

      Actual results:

      Nothing is displayed and sub-shell exits immediately.

      Expected results:

      "hello" will be displayed.

      Additional info:

      It seems to be a problem with the handling of tokens in the input.
      In upstream, the following commit solved the problem.

      --------------------------------------------------------------------
      commit d233b485e83c3a784b803fb894280773f16f2deb (tag: bash-5.0)
      Author: Chet Ramey <chet.ramey@case.edu>
      Date: Mon Jan 7 09:27:52 2019 -0500

      bash-5.0 distribution sources and documentation
      :
      +eval.c
      + - reader_loop: if we're just going to execute one command, make sure
      + the read-ahead token isn't set to something that will result in a
      + NULL command (by calling reset_readahead_token), since the code
      + will take that as the one command and set EOF_Reached
      --------------------------------------------------------------------

      It can be fixed by adding the following code extracted from bash-5.0.

      --------------------------------------------------------------------

      1. cat bash-4.4-fix.patch
          • a/eval.c 2023-08-25 11:35:52.304318084 +0900
            +++ b/eval.c 2023-08-25 11:37:12.593570384 +0900
            @@ -79,6 +79,9 @@ reader_loop ()

      our_indirection_level = ++indirection_level;

      + if (just_one_command)
      + reset_readahead_token ();
      +
      while (EOF_Reached == 0)

      { int code; --- a/parse.y 2023-08-25 11:35:52.349318785 +0900 +++ b/parse.y 2023-08-25 11:38:06.863417857 +0900 @@ -4683,6 +4683,13 @@ token_is_ident (t, i) }

      #endif

      +void
      +reset_readahead_token ()
      +

      { + if (token_to_read == '\n') + token_to_read = 0; +}

      +
      static int
      read_token_word (character)
      int character;
      --------------------------------------------------------------------

              rhn-support-svashish Siteshwar Vashisht
              rhn-support-kyoneyam Kazushige Yoneyama
              Siteshwar Vashisht Siteshwar Vashisht
              Karel Volný Karel Volný
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved: