Bash reference manual 6 (Bash features) Part 2

Source: Internet
Author: User
Tags posix

6.3 Interactive Shell


* What is an interactive shell? What makes a Shel interactive.
* Is it an interactive shell? How to determine whether a shell is interactive.
* What are the differences between Interactive Shell and interactive shell?


6.3.1 what is an interactive shell?
Interactive Shell has no non-option parameters except-s at startup, does not specify the-C option, and the input and error outputs are all connected to the terminal (determined by isatty (3 ), or use the-I option to start the shell.
Interactive Shell generally reads and writes content from the user terminal to the user terminal.
When an interactive shell is started, the-s option is generally used to set location parameters.


6.3.2 is it an interactive shell?
To determine whether bash runs in interactive mode in the script, you need to test the value of the special parameter. When shell is interactive, its value contains I. For example:

case "$-" in*i*) echo This shell is interactive ;;*)   echo This shell is not interactive ;;esac

Or, start the script to check the variable PS1. In non-interactive scripts, It is not set, but set in interactive scripts. For example:
if [ -z "$PS1" ]; then  echo This shell is not interactiveelse  echo This shell is interactivefi


6.3.3 Interactive Shell Behavior
When shell runs in interactive mode, its behavior changes in some aspects.
1. Read and execute the Startup File according to the description in the bash Startup File section.
2. Enable job control by default (see job control ). When the job control is effective, bash ignores the job control signals generated by the keyboard: sigttin, sigttou, and sigtstp.
3. Bash expands and displays PS1 before reading the first line of the command, and extends and displays PS2 before reading the second and subsequent lines of the command.
4. Bash runs the value of prompt_command as a command before printing the prompt $ PS1 (see the bash variable.
5. Readline (see the command line Editing Section) is used to read commands from the user terminal.
6. When bash reads a command, when it receives the EOF from the standard input, it does not exit immediately, but checks the value of ignoreeof the set-O option. (See the "set built-in commands" section)

7. The command history (see the Bash History tools Section) and History extension (see the history interaction section) are enabled by default. When the Interactive Shell exits, bash saves the command history to the file named $ histfile.
8. Alias extension is performed by default (see alias section ).
9. Bash ignores sigterm when there are no other traps (see signal chapter ).
10. If there are no other traps, capture and process Sigint. SIGINT interrupts some built-in shell commands.
11. When the interactive Login Shell exits, if the huponexit option is enabled, the shell sends sighup to all jobs. (See the signal Section)
12. Ignore the-n call option, but 'set-n' has no effect (see the "set built-in command" section ).
13. Bash regularly checks emails, depending on mail, mailpath, and mailcheck variables (see the bash Variable Section ).
14. After 'set-U' is enabled, the shell will not exit due to an extension error that occurs due to reference to the unbound shell variable. (See the "set built-in commands" section)
15. At $ {var :? In word}, the shell does not exit because VaR is not set or the value is null. (See the shell parameter expression Section)
16. The redirection error caused by Shell built-in commands will not cause shell exit.
17. When running in POSIX mode, a specific built-in command returns an error and does not cause shell to exit. (See POSIX Mode)
18. Exec execution fails, and does not cause shell to exit. (See the built-in commands section of the Bourne shell)
19. parsing errors will not cause shell exit.
20. The simple spelling correction function of directory parameters of the CD built-in command is enabled by default. (See the description of the cdspell option of the shopt built-in command in the shopt built-in command section)
21. After printing $ ps1, shell checks the tmout value and exits if the command is not read within the specified number of seconds. (See the shell Variable Section)




Bash reference manual 6 (Bash features) Part 2

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.