diff --git a/tests/virshtest.c b/tests/virshtest.c index 7e59ad7da6..cbe6686af3 100644 --- a/tests/virshtest.c +++ b/tests/virshtest.c @@ -417,6 +417,12 @@ mymain(void) DO_TEST(38, "a\nb\n", "ec\\\nho a\n echo \\\n b;"); DO_TEST(39, "a\n b\n", "\"ec\\\nho\" a\n echo \"\\\n b\";"); DO_TEST(40, "a\n\\\n b\n", "ec\\\nho a\n echo '\\\n b';"); + DO_TEST(41, "a\n", "echo a # b"); + DO_TEST(42, "a\nc\n", "echo a #b\necho c"); + DO_TEST(43, "a\nc\n", "echo a # b\\\necho c"); + DO_TEST(44, "a # b\n", "echo a '#' b"); + DO_TEST(45, "a # b\n", "echo a \\# b"); + DO_TEST(46, "a\n", "#unbalanced; 'quotes\"\necho a # b"); # undef DO_TEST diff --git a/tools/virsh.pod b/tools/virsh.pod index db72343159..05adb568db 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -44,7 +44,8 @@ and their arguments joined with whitespace and separated by semicolons or newlines between commands, where unquoted backslash-newline pairs are elided. 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. +add another layer of shell escaping in creating the single shell argument, +and any word starting with unquoted I<#> begins a comment that ends at newline. If no command is given in the command line, B will then start a minimal interpreter waiting for your commands, and the B command will then exit the program. diff --git a/tools/virt-admin.pod b/tools/virt-admin.pod index 9bbff42846..8489325ca9 100644 --- a/tools/virt-admin.pod +++ b/tools/virt-admin.pod @@ -27,7 +27,8 @@ and their arguments joined with whitespace and separated by semicolons or newlines between commands, where unquoted backslash-newline pairs are elided. Within I, virt-admin 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. +add another layer of shell escaping in creating the single shell argument, +and any word starting with unquoted I<#> begins a comment that ends at newline. If no command is given in the command line, B will then start a minimal interpreter waiting for your commands, and the B command will then exit the program. diff --git a/tools/vsh.c b/tools/vsh.c index 5903f129c1..9a88ee29b7 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -1,7 +1,7 @@ /* * vsh.c: common data to be used by clients to exercise the libvirt API * - * Copyright (C) 2005, 2007-2015 Red Hat, Inc. + * Copyright (C) 2005-2019 Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -1693,6 +1693,12 @@ vshCommandStringGetArg(vshControl *ctl, vshCommandParser *parser, char **res, parser->pos = ++p; /* = \0 or begin of next command */ return VSH_TK_SUBCMD_END; } + if (*p == '#') { /* Argument starting with # is comment to end of line */ + while (*p && *p != '\n') + p++; + parser->pos = p + !!*p; + return VSH_TK_SUBCMD_END; + } while (*p) { /* end of token is blank space or ';' */