From: Richard W.M. Jones Date: Fri, 1 May 2009 16:41:28 +0000 (+0100) Subject: Implement !local in guestfish. X-Git-Tag: 1.0.19~21 X-Git-Url: http://git.annexia.org/?p=libguestfs.git;a=commitdiff_plain;h=a4d88af2c13692e38fb7cfce77b082cee6e0462f Implement !local in guestfish. --- diff --git a/fish/fish.c b/fish/fish.c index fcafb5c..a956bf9 100644 --- a/fish/fish.c +++ b/fish/fish.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #ifdef HAVE_LIBREADLINE @@ -359,6 +360,21 @@ script (int prompt) /* If the next character is '#' then this is a comment. */ if (*buf == '#') continue; + /* If the next character is '!' then pass the whole lot to system(3). */ + if (*buf == '!') { + int r; + + r = system (buf+1); + if (!prompt) { + if (r == -1 || + (WIFSIGNALED (r) && + (WTERMSIG (r) == SIGINT || WTERMSIG (r) == SIGQUIT)) || + WEXITSTATUS (r) != 0) + exit (1); + } + continue; + } + /* Get the command (cannot be quoted). */ len = strcspn (buf, " \t"); diff --git a/guestfish.pod b/guestfish.pod index 746922f..b464c71 100644 --- a/guestfish.pod +++ b/guestfish.pod @@ -189,6 +189,19 @@ but B by a command. For example: Blank lines are also ignored. +=head1 RUNNING COMMANDS LOCALLY + +Any line which starts with a I character is treated as a command +sent to the local shell (C or whatever L uses). +For example: + + !mkdir local + tgz-out /remote local/remote-data.tar.gz + +will create a directory C on the host, and then export +the contents of C on the mounted filesystem to +C. (See C). + =head1 COMMANDS =head2 help