Shell---If statement

Source: Internet
Author: User

Shell tip:

1. Need to add ' $ ' when referencing variables

2.shell variable viewing and deletion

Set | grep variable name//view Set Variable unset variable name//delete variable

The difference between single and double quotes in 3.shell

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/79/4B/wKioL1aN7XfQiFViAAGB_fWKF4E818.jpg "title=" 1.jpg " alt= "Wkiol1an7xfqifviaagb_fwkf4e818.jpg"/>

Note : Single quotation marks are assigned to variables; double quotation mark cancels the function of the space

4. Anti-quotes, assigning a shell command to a variable

650) this.width=650; "src=" http://s5.51cto.com/wyfs02/M01/79/4B/wKioL1aN5OSyUfsXAACbpWRO9k8305.jpg "title=" 2.jpg " alt= "Wkiol1an5osyufsxaacbpwro9k8305.jpg"/>

5.read: Read data, assign to variable

650) this.width=650; "src=" http://s2.51cto.com/wyfs02/M01/79/4B/wKioL1aN5ZCiJRKzAACRHPdpjAw111.jpg "title=" 3.jpg " alt= "Wkiol1an5zcijrkzaacrhpdpjaw111.jpg"/>

6.EXPR: Arithmetic operations on integer variables

650) this.width=650; "src=" http://s1.51cto.com/wyfs02/M02/79/4B/wKioL1aN5hTxLIpwAADzTcWPegg880.jpg "title=" 4.jpg " alt= "Wkiol1an5htxlipwaadztcwpegg880.jpg"/>

Note: Notice the space, \ is escaped, cancels the special meaning of *




If statement:

vim if.sh#!/bin/bash     //specifies that the shell   //script that runs the script begins #file: if.sh      echo  ' Hello, how old are you? ' echo  ' please input your age: ' read age                  //read-in data if [  $age  -eq 28 ];  then        echo  "You ' re at the age of  marriage! " elif [  $age  -gt 28 -a  $age  -lt 35 ]; then      //Judging age between 28 to 35         echo  "You must go  on a blind date now. " elif [  $age  -lt 28 ]; then        echo   "You ' re still young and good to learn!" else        echo  "Sorry, i don ' t kown your age!" fi                                        //script End chmod +x if.sh     //gives execute permission ./if.sh      //script execution script under current path


This article from "Experience from pain" blog, declined reprint!

Shell---If statement

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.