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.