BASH Shell execution, troubleshooting, and startup configuration files

Source: Internet
Author: User

1. Execute bash shell:
(1) Go to the directory where the shell script is located: CD/root/tmp and execute./test. Sh.

(2) execute shell script:/root/tmp/test. Sh in absolute path mode.

(3) run the script CD/root/tmp bash test. Sh, sh test. Sh, or bash/root/tmp/test. Sh directly using bash or sh.

(4) Execute./root/tmp/test. Sh or source/root/tmp/test. Sh in the current shell.
Where, method (1) (2) needs to set the script execution permission: chmod + X test. Sh or chmod 755 test. Sh; Method (3) (4) does not need this step. Method (1) (2) (3) During execution, a subshell is enabled for the current shell. The subshell executes the script of the user and is disabled randomly after execution, return to the current shell; Method (4) is to directly run the script in the current shell, but this method will affect the parent shell environment, which is usually used during system tuning. Method (4) Note that there must be a space between. And!

2. Bash script troubleshooting: Bash-X test. SH: outputs commands and their parameters when executing the script, and traces the execution of the script. Bash-n test. SH: Read the command but not execute it. Bash-V test. SH: Read and print the command;
Account user group, home directory location, default shell in the file/etc/passwd, encrypted password in/etc/shadow.
PS axf: view the hierarchical relationship of various processes in the memory; echo $ shlvl: view the layer-7 shell currently in; Exit: exit this layer shell;

3. bash shell STARTUP configuration file: five running Modes of Bash: Interactive Mode/non-interactive mode (execute script)/call/POSIX mode/restricted function mode with the sh name. 1. log on to the login shell (BASH). Run/etc/profile first, and then check whether the user's main directory contains. bash_profile ,. bash_login ,. profile. If one of them exists, it is read and executed. 2. log out: Bash checks whether. bash_logout exists in the main directory. If yes, it reads and runs it. 3. Execute the new shell: (1) execute the interactive shell: read and execute/etc/bash. bashrc and. bashrc (2) execute shell script: Check the content of the bash_env variable. If so, execute the content of the Startup File defined by the variable. 4. Use sh file name to call Bash: If sh is used to call bash, Bash will follow the old version of sh to call the Startup File. It will try to be compatible with the POSIX standard without using Bash's unique features: (1) login Shell call/bin/sh: read and execute/etc/profile and in the main directory. profile (2) Interactive Shell: Check the content of the env variable. If yes, execute the content of the Startup File defined by the variable. (3) shell script: no startup configuration file is executed. 5. Run Bash -- POSIX: Bash is compatible with POSIX. Check the content of the env variable. If so, execute the content of the Startup File defined by the variable. 6. Execute bash-R or rbash: This mode is called restricted mode. Bash features are limited. For example, you cannot use CD commands, set or cancel environment variables, or perform redirection transmission, the goal is to allow the publisher to have only a few features and establish a secure shell environment. Bash reads the. bashrc configuration file in the main directory.

Related Article

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.