Bug 2134307 - Summary: 'sh' fails to recognize an eval'd alias inside $() command substitution
Summary: Summary: 'sh' fails to recognize an eval'd alias inside $() command substitution
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: Fedora
Classification: Fedora
Component: bash
Version: 36
Hardware: Unspecified
OS: Unspecified
unspecified
high
Target Milestone: ---
Assignee: Siteshwar Vashisht
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2022-10-13 06:28 UTC by Bruce Jerrick
Modified: 2023-01-04 13:52 UTC (History)
7 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2023-01-04 13:52:21 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)
Shell script to demonstrate and document the failure. (958 bytes, application/x-shellscript)
2022-10-13 06:28 UTC, Bruce Jerrick
no flags Details

Description Bruce Jerrick 2022-10-13 06:28:16 UTC
Created attachment 1917725 [details]
Shell script to demonstrate and document the failure.

Description of problem:
As of bash 5.2.2-1, the following fragment from a 'sh' script fails with
  "command not found":

  echo $(eval my_alias)

Version-Release number of selected component:
bash-5.2.2-1

How reproducible:
100%

Steps to Reproduce:
See the attached shell script, meant to be self-explanatory, with caveats:
  The alternative shebang paths will have to be adapted to your test setup.
  The shebang shells include '-u'.  That does not affect the behavior;
    I always include it for safety (imagine 'rm -rf $undef/*' ).

Actual results:
"command not found" failure.

Expected results:
Proper execution of the alias.

Additional info:
bash-5.2.2-2 also fails.
The failure did not occur in bash-5.1.16-3 .
The failure happens only with 'sh', not 'bash'.
The failure also happens in an interactive 'sh'.
In the comments in the attached script, note the difference in the default
  'shopt expand_aliases', 'sh' (on) vs. 'bash' (off).
Behavior is the same with `` as with $() .
Behavior is the same if the $() is quoted: "$()".
Yes, the 'eval' in the attached script is in this case unnecessary, but it
  was triggering the problem in an complex application that did require it.

Comment 1 Bruce Jerrick 2022-10-13 09:19:50 UTC
I just discovered another expansion failure, this time with numeric expansion, not 'eval':

  #!/bin/sh -u
  shopt -s expand_aliases  
  alias narf="echo 123"
  echo $(narf)
  echo $(( $(narf) ))

The first echo works, the second fails with "narf: command not found".
Failure pattern is the same described in attachment 1917725 [details], most importantly:
  Fails with 'sh' from bash-5.2.2-{1,2}
  OK with 'sh' from bash-5.1.16-3
  OK with any 'bash'
(Adapt the shebang path for those versions.)

Comment 2 Bruce Jerrick 2022-12-01 18:53:16 UTC
Neither error (attachment 1917725 [details], or that in comment 1) occurs in bash-5.2.9-3.fc37.x86_64 .

Comment 3 Siteshwar Vashisht 2023-01-04 13:52:21 UTC
Possibly fixed by bash-5.2 patch 7 in upstream[1].

[1] https://git.savannah.gnu.org/cgit/bash.git/commit/?id=6ddc9cf242078c02c626ec60ee139c586da49bad


Note You need to log in before you can comment on or make changes to this bug.