bash scripting using "=" assignment, left and right cannot leave spaces

Source: Internet
Author: User

When assigning a value of "=" to a script variable, "=" cannot have spaces left or right, otherwise it will prompt an error.

For example, the following examples:

 #!/bin/bashbegin_time  = ' date  +%h: %m:%s ".  /a.outend_time  = ' s '  echo   '    " echo   "  $BEGIN _time   " echo   "   " echo   "  $END _time   

When the system time is assigned to Begin_time and Eng_time, in accordance with the previous habit, "=" Left and right to add a space, resulting in an error message:

[email protected] ~/documents $ ./get_time. SH  . /get_time. SH 2 Command not found

Originally for bash scripts, when you assign a value with "=", no spaces can appear on either side of the "=". That

 #!/bin/bashbegin_time  = ' date  +%h: %m:%s ".  /a.outend_time  = ' s '  echo   '    " echo   "  $BEGIN _time   " echo   "   " echo   "  $END _time   

At this point, no error message appears. It can be seen that in bash, the use of spaces should be particularly cautious, or unexpected errors are likely to occur. Refer to the following articles for specific information:

Http://www.jb51.net/article/60328.htm

bash scripting using "=" assignment, left and right cannot leave spaces

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.