diff --git a/tests/virshtest.c b/tests/virshtest.c index cbe6686af3..673c13fe07 100644 --- a/tests/virshtest.c +++ b/tests/virshtest.c @@ -423,6 +423,7 @@ mymain(void) 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"); + DO_TEST(47, "a\n", "\\# ignored;echo a\n'#also' ignored"); # undef DO_TEST diff --git a/tools/virsh.pod b/tools/virsh.pod index 05adb568db..95cab7b57d 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -35,7 +35,8 @@ will be clear for each of those commands. Note: it is permissible to give numeric names to domains, however, doing so will result in a domain that can only be identified by domain id. In other words, if a numeric value is supplied it will be interpreted as a domain id, not -as a name. +as a name. Any I starting with B<#> is treated as a comment +and silently ignored, all other unrecognized Is are diagnosed. 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 diff --git a/tools/virt-admin.pod b/tools/virt-admin.pod index 8489325ca9..f06ee9247a 100644 --- a/tools/virt-admin.pod +++ b/tools/virt-admin.pod @@ -18,7 +18,9 @@ The basic structure of most virt-admin usage is: virt-admin [OPTION]... [ARG]... -Where I is one of the commands listed below. +Where I is one of the commands listed below. Any I +starting with B<#> is treated as a comment and silently ignored, all +other unrecognized Is are diagnosed. 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 diff --git a/tools/vsh.c b/tools/vsh.c index 9a88ee29b7..d90ce8d102 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -1437,8 +1437,15 @@ vshCommandParse(vshControl *ctl, vshCommandParser *parser, vshCmd **partial) } if (cmd == NULL) { - /* first token must be command name */ - if (!(cmd = vshCmddefSearch(tkdata))) { + /* first token must be command name or comment */ + if (*tkdata == '#') { + do { + VIR_FREE(tkdata); + tk = parser->getNextArg(ctl, parser, &tkdata, false); + } while (tk == VSH_TK_ARG); + VIR_FREE(tkdata); + break; + } else if (!(cmd = vshCmddefSearch(tkdata))) { if (!partial) vshError(ctl, _("unknown command: '%s'"), tkdata); goto syntaxError; /* ... or ignore this command only? */