diff options
| author | Craig Jennings <c@cjennings.net> | 2024-04-07 13:41:34 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2024-04-07 13:41:34 -0500 |
| commit | 754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 (patch) | |
| tree | f1190704f78f04a2b0b4c977d20fe96a828377f1 /devdocs/bash/is-this-shell-interactive_003f.html | |
new repository
Diffstat (limited to 'devdocs/bash/is-this-shell-interactive_003f.html')
| -rw-r--r-- | devdocs/bash/is-this-shell-interactive_003f.html | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/devdocs/bash/is-this-shell-interactive_003f.html b/devdocs/bash/is-this-shell-interactive_003f.html new file mode 100644 index 00000000..d01a311e --- /dev/null +++ b/devdocs/bash/is-this-shell-interactive_003f.html @@ -0,0 +1,17 @@ +<h1 class="subsection">Is this Shell Interactive?</h1> <p>To determine within a startup script whether or not Bash is running interactively, test the value of the ‘<samp>-</samp>’ special parameter. It contains <code>i</code> when the shell is interactive. For example: </p> <div class="example"> <pre class="example">case "$-" in +*i*) echo This shell is interactive ;; +*) echo This shell is not interactive ;; +esac +</pre> +</div> <p>Alternatively, startup scripts may examine the variable <code>PS1</code>; it is unset in non-interactive shells, and set in interactive shells. Thus: </p> <div class="example"> <pre class="example">if [ -z "$PS1" ]; then + echo This shell is not interactive +else + echo This shell is interactive +fi +</pre> +</div><div class="_attribution"> + <p class="_attribution-p"> + Copyright © 2000, 2001, 2002, 2007, 2008 Free Software Foundation, Inc.<br>Licensed under the GNU Free Documentation License.<br> + <a href="https://www.gnu.org/software/bash/manual/html_node/Is-this-Shell-Interactive_003f.html" class="_attribution-link">https://www.gnu.org/software/bash/manual/html_node/Is-this-Shell-Interactive_003f.html</a> + </p> +</div> |
