Bug 1022589

Summary: ksh nested command substitution failure
Product: Red Hat Enterprise Linux 6 Reporter: Richard Brittain <richard.brittain>
Component: kshAssignee: Michal Hlavinka <mhlavink>
Status: CLOSED DUPLICATE QA Contact: BaseOS QE - Apps <qe-baseos-apps>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 6.4   
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2013-10-23 16:04:32 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Richard Brittain 2013-10-23 15:16:33 UTC
Description of problem:
Nested command substitutions fail with apparent race condition

Version-Release number of selected component (if applicable):
Name        : ksh                          Relocations: (not relocatable)
Version     : 20100621                          Vendor: Red Hat, Inc.
Release     : 19.el6_4.4                    Build Date: Thu 16 May 2013 09:25:18 AM EDT

How reproducible:
If inner command completes quickly, the combination fails

Steps to Reproduce:
1. Create a file with your own hostname in it, e.g. /etc/hosts
2. line=$(cat /etc/hosts | grep $(hostname))
3.

Actual results:
line=$(cat /etc/hosts | grep $(hostname))
Usage: grep [OPTION]... PATTERN [FILE]...
Try `grep --help' for more information.

Expected results:
matching line from /etc/hosts

Additional info:
If inner command is $(hostname;sleep 1), the commnd works as expected.  This seems to work as expected in bash.

Comment 2 Michal Hlavinka 2013-10-23 16:04:32 UTC

*** This bug has been marked as a duplicate of bug 1011642 ***

Comment 3 Richard Brittain 2013-10-23 16:25:03 UTC
I don't this is the same as the other bug, though they may be related.  I think it is a race condition, nothing to do with ttys.

Another example, not using hostname

Failure:
$ echo $(date | sed -es"/$(date +%Y)/foo/" )
sed: -e expression #1, char 0: no previous regular expression

Success, with enforced delay:
$ echo $(date | sed -es"/$(date +%Y; sleep 1)/foo/" )
Wed Oct 23 12:10:05 EDT foo

Comment 4 Michal Hlavinka 2013-10-24 13:21:14 UTC
Still the same bug.
Original bug has reproducer
echo ok | echo $(hostname) -> no output
echo ok | echo $(hostname; sleep 1) -> correct output

It's about handling list of commands in subshell, no race condition