From nobody Tue May 7 20:05:45 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1550775370638443.58744593528695; Thu, 21 Feb 2019 10:56:10 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C5CC885543; Thu, 21 Feb 2019 18:56:07 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 509B619C58; Thu, 21 Feb 2019 18:56:07 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 4C197181A00A; Thu, 21 Feb 2019 18:56:06 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x1LIu55k008833 for ; Thu, 21 Feb 2019 13:56:05 -0500 Received: by smtp.corp.redhat.com (Postfix) id 4231218FCC; Thu, 21 Feb 2019 18:56:05 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-222.phx2.redhat.com [10.3.116.222]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0C4E460856 for ; Thu, 21 Feb 2019 18:55:59 +0000 (UTC) From: Eric Blake To: libvir-list@redhat.com Date: Thu, 21 Feb 2019 12:55:59 -0600 Message-Id: <20190221185559.16957-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH] virsh: Treat \n like ; in batch mode X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Thu, 21 Feb 2019 18:56:08 +0000 (UTC) Content-Type: text/plain; charset="utf-8" I wanted to do a demonstration with virsh batch mode, which takes multiple commands all packed into a single argument: $ virsh -c test:///default 'echo a; echo b;' a b but that produced a really long line, so I tried to make it more legible: $ virsh -c test:///default ' echo a; echo b; ' error: unknown command: ' ' Let's be more like the shell, and treat unquoted newline as a command separator just as we do for semicolon. In fact, with that, I can even now mix styles: $ virsh -c test:///default ' echo a; echo b echo c ' a b c Fix the grammer in a nearby comment while at it. Signed-off-by: Eric Blake Reviewed-by: John Ferlan --- tools/virsh.pod | 4 ++-- tools/virt-admin.pod | 4 ++-- tools/vsh.c | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/tools/virsh.pod b/tools/virsh.pod index 67edb57b14..2bf1ee77bb 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -40,8 +40,8 @@ as a name. The B program can be used either to run one I by giving the command and its arguments on the shell command line, or a I which is a single shell argument consisting of multiple I actions -and their arguments joined with whitespace, and separated by semicolons -between commands. Within I, virsh understands the +and their arguments joined with whitespace, and separated by semicolons or +newlines between commands. Within I, virsh understands the same single, double, and backslash escapes as the shell, although you must add another layer of shell escaping in creating the single shell argument. If no command is given in the command line, B will then start a min= imal diff --git a/tools/virt-admin.pod b/tools/virt-admin.pod index 3ddbbff934..b2c9a1db6d 100644 --- a/tools/virt-admin.pod +++ b/tools/virt-admin.pod @@ -23,8 +23,8 @@ Where I is one of the commands listed below. The B program can be used either to run one I by givi= ng the command and its arguments on the shell command line, or a I which is a single shell argument consisting of multiple I actions -and their arguments joined with whitespace, and separated by semicolons -between commands. Within I, virt-admin understands the +and their arguments joined with whitespace, and separated by semicolons or +newlines between commands. Within I, virt-admin understan= ds the same single, double, and backslash escapes as the shell, although you must add another layer of shell escaping in creating the single shell argument. If no command is given in the command line, B will then start = a minimal diff --git a/tools/vsh.c b/tools/vsh.c index 610de4495b..3d9bec896b 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -1664,7 +1664,7 @@ vshCommandStringGetArg(vshControl *ctl, vshCommandPar= ser *parser, char **res, if (*p =3D=3D '\0') return VSH_TK_END; - if (*p =3D=3D ';') { + if (*p =3D=3D ';' || *p =3D=3D '\n') { parser->pos =3D ++p; /* =3D \0 or begin of next comman= d */ return VSH_TK_SUBCMD_END; } @@ -1672,7 +1672,7 @@ vshCommandStringGetArg(vshControl *ctl, vshCommandPar= ser *parser, char **res, while (*p) { /* end of token is blank space or ';' */ if (!double_quote && !single_quote && - (*p =3D=3D ' ' || *p =3D=3D '\t' || *p =3D=3D ';')) + (*p =3D=3D ' ' || *p =3D=3D '\t' || *p =3D=3D ';' || *p =3D=3D= '\n')) break; if (!double_quote && *p =3D=3D '\'') { /* single quote */ @@ -1681,7 +1681,7 @@ vshCommandStringGetArg(vshControl *ctl, vshCommandPar= ser *parser, char **res, continue; } else if (!single_quote && *p =3D=3D '\\') { /* escape */ /* - * The same as the bash, a \ in "" is an escaper, + * The same as in shell, a \ in "" is an escaper, * but a \ in '' is not an escaper. */ p++; --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list