Shell (i)

Source: Internet
Author: User

File header

#!/bin/sh

Basic syntax:

Define variables:

Your_name= "Aivy"

In addition to explicitly assigning values directly, you can also assign a value to a variable using a statement:

 for file in ' ls/etc ' or  for file in $ (LS/ETC)

The above statement loops out the file name of the directory under/etc.

Pass Parameters && echo Print:

#!/bin/bashyour_name= "Aivy"' Your name: ' $your _name

Print results----> Your name: Aivy

Process Control Statements:

If Else

Note the point:

    • else if there is no content, there is no need to write
    • The final end needs to be added fi
#!/bin/Basha=10b=20if [$a = = $b   ]then"a equals B"else    "a Not equal to B "fi
For Loop
#!/bin/bash for loop in 1 2 3    4 5 Does "The value is: $loop" Done

Execution Result:

The value is:12345
While statement
#!/bin/shint=1while (($Int.<=5 ))do    echo $  int"    int++" Done

Execution Result:

12345

Until cycle

#!/bin/sha=0! $a-lt ]do   echo $a   "a++"
Done

Execution Result:

0123456789

Case

#!/bin/shanum=1 case    $aNumin 1)  echo ' You selected 1 '    ;;     2)  echo ' You have chosen 2 '    ;;     3)  echo ' You have chosen 3 '    ;;     4)  echo ' You have chosen 4 '    ;;     *)  echo ' You did not enter a number between 1 and 4 '    ;; Esac

Execution Result:

You chose 1.

Shell (i)

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.