Shell script Hollow lattice attention problem: = Assignment can not have spaces on either side, and if comparison judgment = Both sides must be plus a space

Source: Internet
Author: User

The shell script has strict rules for spaces, and there must be no spaces on either side of an assignment statement, and a string comparison with spaces on both sides of the equal sign

When assigning: I=1

i=$ ((i+1))//= must not have spaces on both sides when used as an assignment

When comparing: if [$a = $b]//= as a comparison, there must be spaces on both sides

1, Shell script variable name, equal sign, value cannot have spaces between

The naming must follow the following rules:
The first character must be a letter (a-z,a-z).
You can use an underscore (_) in the middle without spaces.
? punctuation cannot be used.
? You cannot use the keywords in bash (you can view the reserved keywords using the help command).

2. A variable is referenced by a $ symbol plus a variable name, for example:

Echo.. /${prov}/${datdir}

The curly braces outside the variable name are optional, plus the curly braces are used to help the interpreter identify the bounds of the variable, and it is a good habit to add curly braces to all the variables, which is easy to read and error-prone.

Shell script Hollow lattice attention problem: = Assignment can not have spaces on either side, and if comparison judgment = Both sides must be plus a space

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.