Shell Programming Basics

Source: Internet
Author: User
Tags shebang

What is a shell script?

Plain Text Document --the data stored in the document is stored in a character unit;

a large number of command combinations to solve user problems according to user's needs;

"Power of Execution"-the result of the multiple execution of any command is consistent;

Many commands do not have "idempotent", and in shell scripts a large amount of program logic is required to determine whether a command satisfies its operating conditions to avoid serious errors during operation;

The code content in the shell script:

1, the first line must be shebang, the interpreter path, must occupy the absolute beginning of the start, at the execution of the corresponding interpreter to explain the script in the many commands;

#!/bin/bash

#!/bin/sh

#!/usr/bin/python

#!/usr/bin/perl

2, in the shell script, in addition to the Shebang, to # occupy the absolute beginning of the content, are comment lines, the interpreter will ignore the contents of such a line

3, the interpretation line ignores all blank lines in the script;

4, lots of commands and keywords (if,else,then,do,while,for ...)

Note:Once the shell script is running, it is in the current shell according to Shebang's instructions that an interpreter (child shell) is opened to interpret the execution code content, and the content of the shell script is implemented in a child shell process;

we can use text editing tools to write shell scripts:

Nano,vi,vim,emacs,pico recommended use of VIM

under the Convention, the script file name suffix is . SH, also can not add;

How the script works:

1, give execute permission for script file, run this file directly;

chmod +x/path/to/sscript_file

if the write-only file name does not give the path when executing the script, you must ensure that Path variable, you can find the script file.

2, run the interpreter directly, using the script as the parameter of the interpreter command;


Shell Programming Basics

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.