Bug 788486

Summary: virt-edit -e: Bareword found where operator expected
Product: [Community] Virtualization Tools Reporter: Richard W.M. Jones <rjones>
Component: libguestfsAssignee: Richard W.M. Jones <rjones>
Status: CLOSED NOTABUG QA Contact:
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: unspecifiedCC: mbooth, virt-maint
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2012-02-08 10:18:26 UTC Type: ---
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 W.M. Jones 2012-02-08 09:49:09 UTC
Description of problem:

virt-edit -a disk.img /etc/shadow -e 's_^root:.*?:15378:0:99999:7:::_root:$6$SALTsaltUiZikbV3VeeBPsg8./Q5DAfq9aj7CVZMDU6ffBiBLgUEpxv7LMXKbcZ9JSZnYDrZQftdG319XkbLVMvWcF/Vr/:15378:0:99999:7:::_'
Bareword found where operator expected at (eval 1) line 1, near "7::"
	(Missing operator before ::?)
Scalar found where operator expected at (eval 1) line 1, near "$6$SALTsaltUiZikbV3VeeBPsg8"
	(Missing operator before $SALTsaltUiZikbV3VeeBPsg8?)
Having no space between pattern and following word is deprecated at (eval 1) line 1, <STDIN> line 1.
Bareword found where operator expected at (eval 1) line 1, near "7::"
	(Missing operator before ::?)
syntax error at (eval 1) line 1, near "root:"
	...propagated at -e line 1, <STDIN> line 1.

However simply changing the s___ expression to s{}{} causes
the same command to work.

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

1.17.4

How reproducible:

100%

Steps to Reproduce:

(see above)

Comment 1 Richard W.M. Jones 2012-02-08 10:06:19 UTC
After a lot of experimentation, here is a minimal
case for the Bareword error:

$ virt-edit -a disk.img /etc/shadow -e 's_^root:_root:7:::_'
Bareword found where operator expected at (eval 1) line 1, near "7::"
	(Missing operator before ::?)
syntax error at (eval 1) line 1, near "root:"
	...propagated at -e line 1, <STDIN> line 1.

Removing more of the pattern gives just a syntax error:

$ virt-edit -a disk.img /etc/shadow -e 's_^root:_root:_'
syntax error at (eval 1) line 1, near "root:"
	...propagated at -e line 1, <STDIN> line 1.

Comment 2 Richard W.M. Jones 2012-02-08 10:09:34 UTC
The same error happens in plain Perl, eg:

$ perl -e 's_^root:_root:7:::_' /etc/passwd
Bareword found where operator expected at -e line 1, near "7::"
	(Missing operator before ::?)
syntax error at -e line 1, near "root:"
Execution of -e aborted due to compilation errors.

Comment 3 Richard W.M. Jones 2012-02-08 10:16:22 UTC
I think what is happening is that the Perl lexer treats
s_ as a single terminal, not as s followed by a delimiter
underscore.  Naturally that completely changes the meaning
of the expression.

The solution would be to use another delimiter, not _.
Note that it works fine using, eg. s{}{}

Comment 4 Richard W.M. Jones 2012-02-08 10:18:26 UTC
Other suggestions here:
https://rt.perl.org/rt3//Public/Bug/Display.html?id=68804