bug-autoconf
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[sr #110655] AT&T UnixPC (3b1) shell thrown off by #( after case.


From: Alain Knaff
Subject: [sr #110655] AT&T UnixPC (3b1) shell thrown off by #( after case.
Date: Tue, 17 May 2022 08:21:45 -0400 (EDT)

Follow-up Comment #2, sr #110655 (project autoconf):


[comment #1 comment #1:]
> The #( is not needed by any shell I know of. It's there for two reasons: (1)
editors that match parens and get confused by 'case' with unbalanced parens.
(2) Autoconf uses that aren't properly quoted and that also get confused with
'case' with unbalanced parens.

ok, I see

> 
> (1) and (2) together suggest that we should leave the Autoconf code alone.
If you're running on a shell that doesn't do comments correctly, one fix is to
port a working shell and use that instead. You might try bootstrapping 'Bash'
by editing its configure script with 's/#((*$//' and then running 'configure;
make'. Or any other POSIX-confirming shell should do.

On further analysis, I noticed that this code is misinterpreted by the Linux
bash as well.

The only reason why this bug isn't much more apparent is that this code is
only selected in rare cases where "easier" ways (such as plain echo -n) are
not available.

The reason why this is being misinterpreted is because when expanding an
(unquoted) variable, the shell (all shells, even bash on Linux) first breaks
it into individual arguments, using white space (spaces, newlines, tabs,...)
as separators. Eval then pastes those arguments back together, but using plain
space, not what was there to begin with. Which means that the multiline
variable ends up being interpreted as a single long line. That's also the
reason why some lines (such as "arg=$1;") have a semicolon behind them:
without it, the command would merge with the following line!

One fix would be to quote the as_echo_n_body variable. However, this would
also prevent eval to be broken out as the command, so this has to go outside
the quotes, and pasted to the rest via an as_spc environment variable. So the
complete code would like the following:

    as_echo_n_body='
      arg=$1;
      case $arg in #(
      *"$as_nl"*)
        expr "X$arg" : "X\\(.*\\)$as_nl";
        arg=`expr "X$arg" : ".*$as_nl\\(.*\\)"`;;
      esac;
      expr "X$arg" : "X\\(.*\\)" | tr -d "$as_nl"
    '
    export as_echo_n_body
    as_spc=' '
    export as_spc
    as_echo_n='sh -c eval$as_spc"$as_echo_n_body" as_echo'



    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/support/?110655>

_______________________________________________
  Message sent via Savannah
  https://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]