RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 1264077 - Tilda expansion failing in bash
Summary: Tilda expansion failing in bash
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: bash
Version: 7.1
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: rc
: ---
Assignee: Siteshwar Vashisht
QA Contact: BaseOS QE - Apps
URL:
Whiteboard:
Depends On:
Blocks: 1264802 1295396
TreeView+ depends on / blocked
 
Reported: 2015-09-17 12:55 UTC by Martin Kyral
Modified: 2016-05-17 10:46 UTC (History)
4 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of: 802565
: 1264802 (view as bug list)
Environment:
Last Closed: 2016-05-17 10:46:39 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)

Description Martin Kyral 2015-09-17 12:55:53 UTC
The same problem is with bash, too. Under some circumstances, tilda doesn't get expanded properly.

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


+++ This bug was initially created as a clone of Bug #802565 +++

Description of problem:

Tilda expansion fails to take place under certain conditions

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

ksh-20100621-5.el5


How reproducible:

Always


Steps to Reproduce:
1.  create the following script:  (here ~root/bin/date is just a copy of 
    bin/date)

    #!/usr/bin/ksh
    echo $(~root/bin/date)
    ~root/bin/date

2.  Execute the script

Actual results:

The first line prints the date, the second line prints an error because ~root is not getting expanded:

/tmp/ksh.bug[3]: ~root/bin/date: not found [No such file or directory]


Expected results:

Both lines should print the date.




Additional info:

If the second line is commented out, then tilda expansion correctly takes place in the third line and the date is printed.


RHEL 5.8 has ksh93t+.  The bug is also showing up in ksh93u+ and AT&T gave me this patch for 93u+:

--- .../sh/macro.c      Tue Feb  7 09:56:20 2012
+++ sh/macro.c  Fri Mar  9 15:58:54 2012
@@ -2700,7 +2700,12 @@
        if(!logins_tree)
                logins_tree = dtopen(&_Nvdisc,Dtbag);
        if(np=nv_search(string,logins_tree,NV_ADD))
+       {
+               c = shp->subshell;
+               shp->subshell = 0;
                nv_putval(np, pw->pw_dir,0);
+               shp->subshell = c;
+       }
        return(pw->pw_dir);
 }

--- Additional comment from Michal Hlavinka on 2012-03-13 05:30:47 EDT ---

Reproducible and I can confirm that patch fixes this issue.

Modified reproducer:
#!/bin/ksh
cd ${HOME}
TMPDIR=$(mktemp -d test-XXXXXX)
cp /bin/echo ${HOME}/${TMPDIR}/echo
if [ "$(~${USER}/${TMPDIR}/echo OK)$(~${USER}/${TMPDIR}/echo OK)$(~${USER}/${TMPDIR}/echo OK)" = OKOKOK ];
then
  echo "bug fixed"
  rc=0
else
  echo "bug present"
  rc=1
fi
rm -rf ${TMPDIR}
exit $rc

Comment 1 Martin Kyral 2015-09-17 13:01:45 UTC
Version-Release number of selected component (if applicable):

bash-4.2.46-19.el7

Comment 3 Siteshwar Vashisht 2016-05-09 16:48:22 UTC
On RHEL 7 I can see that both bash and ksh show same behaviour :

I have this script under /root/root/bin/ :

# cat /root/root/bin/date
#!/bin/sh
date

and this is the reproducer code :

# cat tmp.sh 
#!/usr/bin/bash
echo $(~root/bin/date)
~root/bin/date

If I execute the reproducer script, both commands expand to '/root/bin/date' :

root@qeos-126 tmp]# ./tmp.sh 
./tmp.sh: line 2: /root/bin/date: No such file or directory

./tmp.sh: line 3: /root/bin/date: No such file or directory


If I modify the script to run ksh instead of bash :
# cat tmp.sh 
#!/usr/bin/ksh
echo $(~root/bin/date)
~root/bin/date

I get same beahviour, both the commands expands to '/root/bin/date' :

./tmp.sh 
./tmp.sh[2]: /root/bin/date: not found [No such file or directory]

./tmp.sh[3]: /root/bin/date: not found [No such file or directory]


What should be the expected behaviour on RHEL 7 ?

Comment 4 Martin Kyral 2016-05-17 10:46:39 UTC
After some investigation I found out that there is no bug. The failing scenario is the following script:

# cat tmp.sh 
#!/usr/bin/ksh
echo $(~${USER}/bin/date)
~${USER}/bin/date

man page says the following about expansion:

The order of expansions is: brace expansion, tilde expansion, parameter, variable and arithmetic  expansion  and  command substitution (done in a left-to-right fashion), word splitting, and pathname expansion.

Because tilde expansion happens before variable expansion (apparently the opposite order is in ksh), the ~${USER} can't be resolved properly and it is expected.

Thus, this is not a bug. Sorry for the fuss.


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