Small problems in Shell programming

Source: Internet
Author: User

1, the variable with = assigned value when the left cannot have spaces. For example , UserName =nihao returns userName: Command not found . Because this place username as a command to deal with. The right approach is to Username=nihao.
Careful is the most important thing, such a small problem is really hard to find. However , when using the Vim editor, the highlight command is white and the variable is green.

2. When reading user input with the read- p command, the variable name after the prompt after-p must have a space. For example read-p "Input your Name:" Name outputs input your name:name, at which time the user's input is not given as expected. The correct approach is to Read-p "Input your Name:" Name (the space before name is required).

3, when using = = for string comparison, = = must have a space before and after, if not, it is always true. For example:

"1" = = "2" ]; Then        echo "Xiangdeng" Else        echo "Budeng" fi

Only output Xiangdeng, must be [["1" = = "2"]] to [["1" = = "2"]].

4, [[]] and [] generally can be replaced, but must be used in =~ [[]]

Small problems in Shell programming

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.