CHAPTE13: Learning shell Scripts (1) Simple shell scripts

Source: Internet
Author: User

The simple thing is to write some shell syntax and commands in it, plus regular expressions, pipeline commands, and data flow redirection to achieve the purpose we want.

Shell scripts is a good tool for system administration, but it is not fast enough to handle a large number of computations and uses more CPU resources.

One. The first scripts is written and executed

Suppose we write the first scripts file named Shell.sh and execute the following methods:

(1) Direct command execution: The shell.sh file must have Rx (Read and execute) permission.

Absolute path:/home/chuiyuan/shell.sh

Relative path: Under/home/chuiyuan, use./shell.sh

Variable path function: Place shell.sh under Path specified by path, such as ~/bin (this directory is set by itself)

(2) Execute with bash: You can only have Read permission at this time.

Executed via bash shell.sh or sh shell.sh. This means that the system wants to execute commands in this file with bash functionality.

Shell files can use-N and-X to view the syntax.

Example:

The first line declares that we are using the bash syntax, which must have the ability to load bash-related configuration files (typically the Non-login Shell's ~/.BASHRC) and execute bash to enable our commands to execute. Otherwise the program will not know what shell to use.

The environment variable is set here so that the program can execute some external commands directly while it is in progress, without having to write absolute paths.

The last line indicates that the program is terminated and a 0 is returned to the system to indicate successful execution. We can also use Exit N for customization.

Note that the permissions for the program are read-only at this time

So you can only use bash to perform

To use a direct path to execute, change the permissions

CHAPTE13: Learning shell Scripts (1) Simple shell scripts

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.