This service will be undergoing maintenance at 00:00 UTC, 2016-08-01. It is expected to last about 1 hours
Bug 503134 - guestfish's list splitting does not recognize internal quoting
guestfish's list splitting does not recognize internal quoting
Status: ASSIGNED
Product: Virtualization Tools
Classification: Community
Component: libguestfs (Show other bugs)
unspecified
All Linux
low Severity low
: ---
: ---
Assigned To: Richard W.M. Jones
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2009-05-29 02:56 EDT by Charles Duffy
Modified: 2010-05-12 08:00 EDT (History)
4 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed:
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:


Attachments (Terms of Use)

  None (edit)
Description Charles Duffy 2009-05-29 02:56:28 EDT
Richard W.M. Jones wrote:
> On Thu, May 28, 2009 at 05:41:44PM -0500, Charles Duffy wrote:
>> What's the Right Way to do the below?
>>
>>> <fs> command "bash -c 'for D in avahi-daemon avahi-dnsconfd haldaemon;  
>> do /sbin/chkconfig $D off; done; true'"
>> libguestfs: error: D: -c: line 0: unexpected EOF while looking for  
>> matching `''
>> D: -c: line 1: syntax error: unexpected end of file
>
> The problem is that guestfish's list splitting code sucks, so
> the above turns into the equivalent of this API call:
>
> guestfs_command (g, "bash", "-c", "'for", "D", "in",
> 		"avahi-daemon", "avahi-dnsconfd", "haldaemon;",
> 		"do", "/sbin/chkconfig", "$D", "off;", "done;", "true'");
>
> Please file a bug about this.

Behavior should be closer to that of the actual shell, or python's "shlex", preserving quoted strings as individual tokens. (Alternately, system() could be used in place of an exec call, such that the tokenizing is done by an _actual_ shell within the guest).
Comment 1 Richard W.M. Jones 2009-05-29 06:28:30 EDT
The syntax I was thinking of using was:

["foo", "bar"]

guestfish doesn't include a real scanner, instead it
splits on whitespace.  However it checks the first character
of each argument and modifies its behaviour accordingly.
For example, if the first character is ' or " then instead
of blindly splitting, it searchs for the corresponding close-quote.

So with the syntax above, if the first character after whitespace
was an opening [ then we would parse the rest as comma-separated
strings until a matching ] was found.

(The alternative would be to use lex and write a real scanner,
but we'd need to be careful not to break existing scripts).
Comment 2 Richard W.M. Jones 2009-06-22 02:51:32 EDT
This cset adds support for 'sh' and 'sh-lines' commands
which should alleviate this problem.

http://git.et.redhat.com/?p=libguestfs.git;a=commitdiff;h=57d2dfab18ad3d987d9273bb7c1f42e73e0bbcb2

Example usage:

 ><fs> sh "echo /s*"
 /sbin /selinux /srv /sys
 
 ><fs> sh-lines "ls -1d /s*"
 /sbin
 /selinux
 /srv
 /sys

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