Linux shell Programming

Source: Internet
Author: User

1. Variable and variable values (expanded)

If you need a variable name, use the variable name directly, or if you need a variable value, use the $ symbol. For example:

Export Path=/home/bin: $PATH

If you're not sure if you want the variable or expanded variable value, try expanding the next-generation expression to see what's wrong.

In general, where the lvalue is required (assigning values to variables) directly with the variable name, where the right value is required (the value of the variable) plus the $ symbol.

2. Variable assignment, do not add a space before and after the equal number.

3 Separating variables and suffixes:

${go}ing

4. Shell wildcard characters and quotation marks

4.1 No quotation marks

For example, LS *.*,shell will expand *. * to all files in the current directory and then pass it to LS.

4.2 Double Quotes

If you use LS "* *", the shell will pass *. * to Ls,ls and will tell you that there is no file whose filename is *. *

However, if the $ symbol is present in double quotes, the shell will still explain.

4.3 single quotation marks

Well, now even $ does not explain.

5. C-style expressions

#!/bin/bash

var=2 # The default variable type is string and cannot be directly mathematically operated

echo $ ((var * var)) # ((C stype expression)), put in two parentheses, you can add a space before and after the operator, take the variable value does not need $, the calculated new variable still with the $ reference to echo

echo $var # var value is still 2, unchanged. If the previous line is $ ((var++)), then this line is 3.

Linux 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.