Learn more about Linux Shell Scripting Basics (i)

Source: Internet
Author: User
Basics of Linux Shell scripting here we first talk about the shell of the basic syntax, the beginning, comments, variables and environment variables, to do a basic introduction, although not related to specific things, but lay the foundation is to learn easily after the premise.
1. Linux Scripting Basics
Basic Introduction to 1.1 grammar
1.1.1 Opening

The program must start with the following line (must be in the first line of the file):
#!/bin/sh
The symbol #! is used to tell the system that the parameter behind it is the program used to execute the file. In this example we use/BIN/SH to execute the program.
When you edit a script, you must also make it executable if you want to execute the script.
To make the script executable:
Compile chmod +x filename so you can use./filename to run
1.1.2 Notes
In shell programming, a sentence that begins with # represents a comment until the end of the line. We sincerely recommend that you use annotations in your programs.
If you use annotations, you can understand the script's function and how it works in a very short time, even if you haven't used the script for quite a long period of time.
1.1.3 Variable

In other programming languages, you must use variables. In shell programming, all variables are made up of strings, and you do not need to declare the variables. To assign a value to a variable, you can write:
#!/bin/sh
#对变量赋值:
A= "Hello World"
# now print the contents of variable a:
echo "A is:"
Echo $a
Sometimes variable names are easily confused with other words, such as:
num=2
echo "The $numnd"
This does not print out "This is the 2nd" and simply prints "This is the" because the shell will go to search for the value of the variable numnd, but this variable has no value. You can use curly braces to tell the shell that we're printing num variables:
num=2
echo "This is the ${num}nd"
This will print: This is the 2nd
1.1.4 Environment variables
Variables processed by the EXPORT keyword are called environment variables. We do not discuss environment variables, because environment variables are typically used only in logon scripts.
This is explained here, and below we will be exposed to the substantive parts of the specific Linux Shell Script Foundation.

The above is the detailed introduction of the Linux shell Script Basic Learning (a), more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!

  • 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.