bash:check_if_bash_is_running_in_interactive_mode
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
bash:check_if_bash_is_running_in_interactive_mode [2021/02/04 10:38] – created peter | bash:check_if_bash_is_running_in_interactive_mode [2021/02/04 11:08] (current) – [BASH - Check if bash is running in interactive mode] peter | ||
---|---|---|---|
Line 5: | Line 5: | ||
then | then | ||
do_interactive_stuff | do_interactive_stuff | ||
+ | fi | ||
+ | |||
+ | |||
+ | if [ " | ||
+ | ... | ||
fi | fi | ||
</ | </ | ||
Line 15: | Line 20: | ||
</ | </ | ||
+ | ---- | ||
+ | |||
+ | ====== Check if standard input is a TTY ====== | ||
+ | |||
+ | <code bash> | ||
+ | if [ -t 0 ] ; then | ||
+ | echo stdin is a terminal | ||
+ | ..... | ||
+ | fi | ||
+ | </ | ||
+ | |||
+ | or | ||
+ | |||
+ | <code bash> | ||
+ | if [ -t 1 ] ; then | ||
+ | echo stdout is a terminal | ||
+ | fi | ||
+ | </ | ||
+ | |||
+ | <WRAP info> | ||
+ | **NOTE: | ||
+ | |||
+ | Portable between shells. | ||
+ | </ | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ===== Examples ===== | ||
+ | |||
+ | <code bash> | ||
+ | bash <<< | ||
+ | </ | ||
+ | |||
+ | writes X | ||
+ | |||
+ | <code bash> | ||
+ | bash -c 'test -t 0 && echo Y || echo X | ||
+ | </ | ||
+ | |||
+ | writes Y | ||
+ | |||
+ | <WRAP info> | ||
+ | **NOTE: | ||
+ | </ | ||
+ | |||
+ | |||
+ | ---- |
bash/check_if_bash_is_running_in_interactive_mode.1612435119.txt.gz · Last modified: 2021/02/04 10:38 by peter