summaryrefslogtreecommitdiff
path: root/devdocs/bash/is-this-shell-interactive_003f.html
diff options
context:
space:
mode:
Diffstat (limited to 'devdocs/bash/is-this-shell-interactive_003f.html')
-rw-r--r--devdocs/bash/is-this-shell-interactive_003f.html17
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 &copy; 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>