Difference between revisions of "Bash:ScriptExamples"
Jump to navigation
Jump to search
(Created page with "Category:Bash =Check interactive shell= To check within a startup script (like .bashrc) whether or not Bash is running interactively. Test if $- has an 'i' in it or if $P...") |
m |
||
Line 1: | Line 1: | ||
− | [[Category: | + | [[Category:Linux/Unix]] |
=Check interactive shell= | =Check interactive shell= |
Latest revision as of 11:40, 20 January 2022
Check interactive shell
To check within a startup script (like .bashrc) whether or not Bash is running interactively. Test if $- has an 'i' in it or if $PS1 (the prompt) exists.
case "$-" in
*i*) echo This shell is interactive ;;
*) echo This shell is not interactive ;;
esac
if [ -z "$PS1" ]; then
echo This shell is not interactive
else
echo This shell is interactive