Next: Logging Output, Previous: Quitting GDB, Up: Invocation [Contents][Index]

### 2.3 Shell Commands

If you need to execute occasional shell commands during your debugging session, there is no need to leave or suspend GDB; you can just use the `shell` command.

`shell command-string`
`!command-string`

  Invoke a standard shell to execute command-string. Note that no space is needed between `!` and command-string. On GNU and Unix systems, the environment variable `SHELL`, if it exists, determines which shell to run. Otherwise GDB uses the default shell (`/bin/sh` on GNU and Unix systems, `cmd.exe` on MS-Windows, `COMMAND.COM` on MS-DOS, etc.).

The utility `make` is often needed in development environments. You do not have to use the `shell` command for this purpose in GDB:

`make make-args`

  Execute the `make` program with the specified arguments. This is equivalent to ‘`shell make make-args`’.

`pipe [command] | shell_command`
`| [command] | shell_command`
`pipe -d delim command delim shell_command`
`| -d delim command delim shell_command`

  Executes command and sends its output to shell_command. Note that no space is needed around `|`. If no command is provided, the last command executed is repeated.

  In case the command contains a `|`, the option `-d delim` can be used to specify an alternate delimiter string delim that separates the command from the shell_command.

  Example:

      (gdb) p var
      $1 = {
        black = 144,
        red = 233,
        green = 377,
        blue = 610,
        white = 987
      }

      (gdb) pipe p var|wc
            7      19      80
      (gdb) |p var|wc -l
      7

      (gdb) p /x var
      $4 = {
        black = 0x90,
        red = 0xe9,
        green = 0x179,
        blue = 0x262,
        white = 0x3db
      }
      (gdb) ||grep red
        red => 0xe9,

      (gdb) | -d ! echo this contains a | char\n ! sed -e 's/|/PIPE/'
      this contains a PIPE char
      (gdb) | -d xxx echo this contains a | char!\n xxx sed -e 's/|/PIPE/'
      this contains a PIPE char!
      (gdb)

The convenience variables `$_shell_exitcode` and `$_shell_exitsignal` can be used to examine the exit status of the last shell command launched by `shell`, `make`, `pipe` and `|`. See Convenience Variables.

Next: Logging Output, Previous: Quitting GDB, Up: Invocation [Contents][Index]