| 1 | /* Evaluate a string as one or more shell commands.
|
|---|
| 2 |
|
|---|
| 3 | Copyright (C) 1996-2005 Free Software Foundation, Inc.
|
|---|
| 4 |
|
|---|
| 5 | This file is part of GNU Bash, the Bourne Again SHell.
|
|---|
| 6 |
|
|---|
| 7 | Bash is free software; you can redistribute it and/or modify it under
|
|---|
| 8 | the terms of the GNU General Public License as published by the Free
|
|---|
| 9 | Software Foundation; either version 2, or (at your option) any later
|
|---|
| 10 | version.
|
|---|
| 11 |
|
|---|
| 12 | Bash is distributed in the hope that it will be useful, but WITHOUT ANY
|
|---|
| 13 | WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|---|
| 14 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|---|
| 15 | for more details.
|
|---|
| 16 |
|
|---|
| 17 | You should have received a copy of the GNU General Public License along
|
|---|
| 18 | with Bash; see the file COPYING. If not, write to the Free Software
|
|---|
| 19 | Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
|
|---|
| 20 |
|
|---|
| 21 | #include <config.h>
|
|---|
| 22 |
|
|---|
| 23 | #if defined (HAVE_UNISTD_H)
|
|---|
| 24 | # ifdef _MINIX
|
|---|
| 25 | # include <sys/types.h>
|
|---|
| 26 | # endif
|
|---|
| 27 | # include <unistd.h>
|
|---|
| 28 | #endif
|
|---|
| 29 |
|
|---|
| 30 | #include <stdio.h>
|
|---|
| 31 | #include <signal.h>
|
|---|
| 32 |
|
|---|
| 33 | #include <errno.h>
|
|---|
| 34 |
|
|---|
| 35 | #include "filecntl.h"
|
|---|
| 36 | #include "../bashansi.h"
|
|---|
| 37 |
|
|---|
| 38 | #include "../shell.h"
|
|---|
| 39 | #include "../jobs.h"
|
|---|
| 40 | #include "../builtins.h"
|
|---|
| 41 | #include "../flags.h"
|
|---|
| 42 | #include "../input.h"
|
|---|
| 43 | #include "../execute_cmd.h"
|
|---|
| 44 | #include "../redir.h"
|
|---|
| 45 | #include "../trap.h"
|
|---|
| 46 |
|
|---|
| 47 | #if defined (HISTORY)
|
|---|
| 48 | # include "../bashhist.h"
|
|---|
| 49 | #endif
|
|---|
| 50 |
|
|---|
| 51 | #include "common.h"
|
|---|
| 52 |
|
|---|
| 53 | #if !defined (errno)
|
|---|
| 54 | extern int errno;
|
|---|
| 55 | #endif
|
|---|
| 56 |
|
|---|
| 57 | #define IS_BUILTIN(s) (builtin_address_internal(s, 0) != (struct builtin *)NULL)
|
|---|
| 58 |
|
|---|
| 59 | extern int indirection_level, startup_state, subshell_environment;
|
|---|
| 60 | extern int line_number;
|
|---|
| 61 | extern int last_command_exit_value;
|
|---|
| 62 | extern int running_trap;
|
|---|
| 63 | extern int loop_level;
|
|---|
| 64 | extern int posixly_correct;
|
|---|
| 65 |
|
|---|
| 66 | int parse_and_execute_level = 0;
|
|---|
| 67 |
|
|---|
| 68 | static int cat_file __P((REDIRECT *));
|
|---|
| 69 |
|
|---|
| 70 | /* How to force parse_and_execute () to clean up after itself. */
|
|---|
| 71 | void
|
|---|
| 72 | parse_and_execute_cleanup ()
|
|---|
| 73 | {
|
|---|
| 74 | if (running_trap)
|
|---|
| 75 | {
|
|---|
| 76 | run_trap_cleanup (running_trap - 1);
|
|---|
| 77 | unfreeze_jobs_list ();
|
|---|
| 78 | }
|
|---|
| 79 | run_unwind_frame ("parse_and_execute_top");
|
|---|
| 80 | }
|
|---|
| 81 |
|
|---|
| 82 | /* Parse and execute the commands in STRING. Returns whatever
|
|---|
|
|---|