Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.
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 1067034

Summary: Augeas lens bug: shellvars and case statements with same-line ;; tokens
Product: Red Hat Enterprise Linux 7 Reporter: Pat Riehecky <riehecky>
Component: augeasAssignee: Dominic Cleal <dcleal>
Status: CLOSED DUPLICATE QA Contact: Virtualization Bugs <virt-bugs>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 7.0CC: asanders, dcleal, fkrska, lkong, mkolaja
Target Milestone: rc   
Target Release: ---   
Hardware: All   
OS: Linux   
URL: https://github.com/hercules-team/augeas/pull/77
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: 1033799 Environment:
Last Closed: 2014-02-19 14:33:55 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 Pat Riehecky 2014-02-19 14:30:46 UTC
+++ This bug was initially created as a clone of Bug #1033799 +++

Description of problem:
The shellvars lens fails to load a file that has a case statement with the trailing ;; on the same line as an entry.

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

How reproducible:


Steps to Reproduce:
1. Create a file that has ";;" on the same line as its entry


root@test:/u/test $ cat test_case_singleline.shellvars 
case $ARG in
        0) TestVar="test0" ;;
        1) TestVar="test1" ;;
esac
2. Run "augtool --noautoload", attempt to load the file, then print the shell variables:
root@test:/u/test $ augtool --noautoload
augtool> set /augeas/load/test/lens "Shellvars.lns"
augtool> set /augeas/load/test/incl /u/test/test_case_singleline.shellvars
augtool> load
augtool> print /files/u/test/test_case_singleline.shellvars
augtool>

Actual results:
The file is not loaded even though the file contains valid shell syntax.

Expected results:
The file IS loaded and the variables can be printed *without* having the ";;" on a separate line:

Having the ";;" on a new line works correctly
root@test:/u/test $ cat test_case_multiine.shellvars 
case $ARG in
        0) TestVar="test0" 
                ;;
        1) TestVar="test1" 
                ;;
esac

root@test:/u/test $ augtool --noautoload
augtool> set /augeas/load/test/lens "Shellvars.lns"
augtool> set /augeas/load/test/incl /u/test/test_case_multiine.shellvars
augtool> load
augtool> print /files/u/test/test_case_multiine.shellvars
/files/u/test/test_case_multiine.shellvars
/files/u/test/test_case_multiine.shellvars/@case = "$ARG"
/files/u/test/test_case_multiine.shellvars/@case/@case_entry[1] = "0"
/files/u/test/test_case_multiine.shellvars/@case/@case_entry[1]/TestVar = "\"test0\""
/files/u/test/test_case_multiine.shellvars/@case/@case_entry[2] = "1"
/files/u/test/test_case_multiine.shellvars/@case/@case_entry[2]/TestVar = "\"test1\""
augtool>

Additional info: None.

--- Additional comment from RHEL Product and Program Management on 2013-11-27 04:16:25 EST ---

This request was not resolved in time for the current release.
Red Hat invites you to ask your support representative to
propose this request, if still desired, for consideration in
the next release of Red Hat Enterprise Linux.

--- Additional comment from Lingfei Kong on 2014-01-07 22:08:07 EST ---

Can reproduce with augeas-1.0.0-5.el6.

Steps to reproduce:
1. Create a file that has ";;" on the same line as its entry
[host-c]#cat test.txt 
case $ARG in
    0) TestVar="test0" ;;
    1) TestVar="test1" ;;
esac

2. Run "augtool --noautoload", load the file, then print the shell variables:
[host-c]#augtool --noautoload
augtool> set /augeas/load/test/lens "Shellvars.lns"
augtool> set /augeas/load/test/incl /root/test.txt
augtool> load
augtool> print /files/root/test.txt
augtool> quit

The file is not loaded. 

----------------------------------------------------------
Having the ";;" on a new line works correctly
[host-c]#cat test.txt 
case $ARG in
    0) TestVar="test0" 
        ;;
    1) TestVar="test1" 
        ;;
esac
[host-c]#augtool --noautoload
augtool> set /augeas/load/test/lens "Shellvars.lns"
augtool> set /augeas/load/test/incl /root/test.txt
augtool> load
augtool> print /files/root/test.txt
/files/root/test.txt
/files/root/test.txt/@case = "$ARG"
/files/root/test.txt/@case/@case_entry[1] = "0"
/files/root/test.txt/@case/@case_entry[1]/TestVar = "\"test0\""
/files/root/test.txt/@case/@case_entry[2] = "1"
/files/root/test.txt/@case/@case_entry[2]/TestVar = "\"test1\""

This time the file is loaded.

--- Additional comment from Filip Krska on 2014-01-29 06:03:53 EST ---

Proposing patch adding support for (reasonable subset of) oneliners in case entries.

However, I treat this rather as a quick non-invasive dirty fix of this particular hot use case than a final fix.

IMHO all entries should be defined according to shell's "list" philosophy i.e. not ending with comment_or_eol and occurrences of entry* should be replaced with something like `(entry . comment_or_eol)*` where ; or eol is mandatory and `(entry . comment_or_eol)* . entry?` where optional.

--- Additional comment from Dominic Cleal on 2014-01-29 18:05:15 EST ---

(In reply to Filip Krska from comment #11)
> Created attachment 857011 [details]
> support for oneliners in case
> 
> Proposing patch adding support for (reasonable subset of) oneliners in case
> entries.
> 
> However, I treat this rather as a quick non-invasive dirty fix of this
> particular hot use case than a final fix.

Agreed, this works and should be used in the meantime.  Good work.

> IMHO all entries should be defined according to shell's "list" philosophy
> i.e. not ending with comment_or_eol and occurrences of entry* should be
> replaced with something like `(entry . comment_or_eol)*` where ; or eol is
> mandatory and `(entry . comment_or_eol)* . entry?` where optional.

I've got a rough patch working in this style now, but it's a bit trickier since the comment_or_eol has to be within the entry subtrees to avoid ambiguity.

--- Additional comment from Dominic Cleal on 2014-02-10 05:43:39 EST ---

a1b9831d14f22f81cf7dc840160c08cc14234ee9 upstream.

Comment 1 Dominic Cleal 2014-02-19 14:33:55 UTC
Thanks Pat, this is already fixed in RHEL 7.  Sorry, the bug was made private.

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