27.08.2015 Views

Advanced Bash−Scripting Guide

Advanced Bash-Scripting Guide - Nicku.org

Advanced Bash-Scripting Guide - Nicku.org

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>Advanced</strong> <strong>Bash−Scripting</strong> <strong>Guide</strong><br />

restores the original $PATH (a child process, such as a script, may not change the environment of the<br />

parent process, the shell).<br />

The current "working directory", ./, is usually omitted from the $PATH as a security<br />

measure.<br />

$PIPESTATUS<br />

Exit status of last executed foreground pipe. Interestingly enough, this does not give the same result<br />

as the exit status of the last executed command.<br />

bash$ echo $PIPESTATUS<br />

0<br />

bash$ ls −al | bogus_command<br />

bash: bogus_command: command not found<br />

bash$ echo $PIPESTATUS<br />

141<br />

bash$ ls −al | bogus_command<br />

bash: bogus_command: command not found<br />

bash$ echo $?<br />

127<br />

The $PIPESTATUS variable may contain an erroneous 0 value in a login shell.<br />

tcsh% bash<br />

bash$ who | grep nobody | sort<br />

bash$ echo ${PIPESTATUS[*]}<br />

0<br />

The above lines contained in a script would produce the expected 0 1 0 output.<br />

$PPID<br />

Thank you, Wayne Pollock for pointing this out and supplying the above example.<br />

The $PPID of a process is the process id (pid) of its parent process. [19]<br />

$PS1<br />

$PS2<br />

$PS3<br />

$PS4<br />

$PWD<br />

Compare this with the pidof command.<br />

This is the main prompt, seen at the command line.<br />

The secondary prompt, seen when additional input is expected. It displays as ">".<br />

The tertiary prompt, displayed in a select loop (see Example 10−29).<br />

The quartenary prompt, shown at the beginning of each line of output when invoking a script with the<br />

−x option. It displays as "+".<br />

working directory (directory you are in at the time)<br />

This is the analog to the pwd builtin command.<br />

Chapter 9. Variables Revisited 68

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!