How to use shell programming hollow lattice _linux shell

Source: Internet
Author: User

1. When defining a variable, no spaces can be left on either side of the = number.
eg:
Gender=femal ———— Right
Gender =femal ——— –wrong
gender= femal ——— –wrong
2. Conditional test statement [Both sides of the symbol must be left blank.
eg:
if [$gender = Femal]; Then ——-right.
echo "You are Femal";
Fi

if[$gender ...-----------------------wrong
If [$gender ...----------------------wrong.

3. The content of the condition test, if it is a string comparison, the comparison symbol on both sides should be left blank!
eg:
if [$gender = Femal]; Then ——-right.
if [$gender = Femal]; Then--–wrong.
If [$gender =femal]; Then ——— wrong.

4. If the IF and then are written on the same line, then, note that the front of the then to keep up; If the then line is written, then there is no problem.
eg:
if [$gender = Femal]; Then ——-right.
if [$gender = Femal]
Then ——————————-right.
if [$gender = Femal] then ——-wrong. The then front is less; Resolution.
Prompt for error message:
Syntax error near unexpected token then
Similarly, there are many error messages such as
Syntax error near unexpected token fi, etc. are caused by this.

Be sure to keep up with then after 5.if. Similarly
Be sure to keep up with then after Elif.
Otherwise prompt for error message:
Syntax error near unexpected token else

1 if statement followed by then, and preceded by a semicolon;
2 space is very important, the shell will think that the space before a command, if A=3 think is an assignment operation, if written a = 3, then think of a as a command this= ' ls-l |grep ' ^-' | Wc-l '
3 The operator should be separated by a space, such as test! -D $, of which! And-D will be separated by a space
A space is an important separator in command resolution

6. There must be a space between the command and subsequent arguments or objects

If [-X "~/workspace/shell/a.sh"];then


A null Gecay indicates whether the string immediately following it points to an executable file name, otherwise the test-X "~/workspace/shell/a.sh" is not empty.

7. The symbol ' $ ' of the variable value and the variable or parenthesis behind it cannot have spaces

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.