mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-21 22:53:37 +00:00
Implement !local in guestfish.
This commit is contained in:
16
fish/fish.c
16
fish/fish.c
@@ -26,6 +26,7 @@
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <getopt.h>
|
||||
#include <signal.h>
|
||||
#include <assert.h>
|
||||
|
||||
#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");
|
||||
|
||||
|
||||
@@ -189,6 +189,19 @@ but B<not> 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</bin/sh> or whatever L<system(3)> uses).
|
||||
For example:
|
||||
|
||||
!mkdir local
|
||||
tgz-out /remote local/remote-data.tar.gz
|
||||
|
||||
will create a directory C<local> on the host, and then export
|
||||
the contents of C</remote> on the mounted filesystem to
|
||||
C<local/remote-data.tar.gz>. (See C<tgz-out>).
|
||||
|
||||
=head1 COMMANDS
|
||||
|
||||
=head2 help
|
||||
|
||||
Reference in New Issue
Block a user