blob: d01a311e03da935f47443c20e810fb9d94793a31 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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>
|