Linux Shell variables and linuxshell Variables

Source: Internet
Author: User

Linux Shell variables and linuxshell Variables

M @ meng :~ $ B = 2 + 3 m @ meng :~ $ Echo $ b2 + 3

However, the declare command can be used to set the type of a variable. Currently, only integer and array types are supported. Now, consider integer. The declare-I a command sets the type of variable a to integer. In this way, the arithmetic expression assigned to a is no longer considered as a normal string but a real number, a can also participate in arithmetic operations as follows:

M @ meng :~ $ A = 2 + 3 m @ meng :~ $ Echo $ a5m @ meng :~ $ A = $ a + $ bm @ meng :~ $ Echo $ a10

Obviously, the 2 + 3 of $ B is also regarded as a number. Of course, more than this method can be used to perform arithmetic operations. The let Command and expr command can also achieve the goal. We will introduce it later.

The key point here is that the value of a variable is a problem caused by the default character string: Sometimes we need to assign the output result of a command to the variable, for example, if you assign the result of the date command to the NOW variable, the direct method is:

M @ meng :~ $ NOW = datem @ meng :~ $ Echo $ NOWdate

Does not reach the expected result, because date is considered as a normal string. So shell introduces a mechanism to avoid this situation, that is, anti-quotation marks:

M @ meng :~ $ NOW = 'date' m @ meng :~ $ Echo $ NOW Monday June 22, 2015 12:26:53 CST

Put the command in the back quotes, the command will not be a common string, but a real command, it will generate the output, but not display it on the standard output,Redirect to variable.

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.