Shell Scripting Learning (ii)

Source: Internet
Author: User

Linux-bash types of editing languages for script editing

Interpreted language (Bash Python perl)

definition: Use the interpreter to read the code we write and convert it into system-related commands. Executive advantage: It's easy to deal with objects like files or directories disadvantage: Slow execution

Compiled languages: (c; c + +; java) definition: compiled. Then perform the following advantages: responsible for the underlying correlation, such as bytes, certificates, floating point objects such as. Bash script ends in. sh Python with. Py End

####### Cat/etc/shells

/bin/bash

#!/bin/bash

PAH Export PATH Command

Exit 0

Show Command Execution status value:echo $?

0: Normal execution 1: Error 126: System call occurs error 127: System unrecognized command 130:ctrl+c

Check script syntax: bash-n file.sh Check script;

Debug Debug of Bash-x file.sh script;

How bash scripts are executed: 1.bash xxxx

2. Add Execute permissions (x)./file.sh

3.~/.bashrc

Cat/etc/redhat-release View the Linux version,

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/4D/F8/wKiom1ReAXLghimrAAFwbGEvcmU131.jpg "title=" Aaa.png "alt=" Wkiom1reaxlghimraafwbgevcmu131.jpg "/>


Bash's variables:

#hu =linux

Echo ' Hu '

Bash the basic loop syntax

1 , for variables inch List

Do

Loop Body

Done

For example:

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/4D/F8/wKiom1ReBB3g6RizAADDv9-Fj28107.jpg "title=" vv.png "alt=" Wkiom1rebb3g6rizaaddv9-fj28107.jpg "/>650) this.width=650; src=" http://s3.51cto.com/wyfs02/M00/4D/F8/ Wkiom1rebedhyxqxaabjzpcwfpg525.jpg "title=" Ww.png "alt=" Wkiom1rebedhyxqxaabjzpcwfpg525.jpg "/>


The list here is generated in a number of ways:

I,{startnumber. Endnumber}

For example: {1..100} ,1 to 100

II. Using the seq command

Seq Startnumber Step Endnumber

When using seq , you use a command reference

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/4D/F7/wKioL1ReBcajrH5cAACzTLuS7MY435.jpg "title=" Qqqq.png "alt=" Wkiol1rebcajrh5caacztlus7my435.jpg "/>


650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/4D/F8/wKiom1ReBbeA5bSnAACbdo2qN-g381.jpg "title=" Sss.png "alt=" Wkiom1rebbea5bsnaacbdo2qn-g381.jpg "/>

This script generates an odd number of files, i.e. file1 , File3,seq the command reference is in anti-quotes, and the stepping value is 2

III, can also be all positional variables [email protected]

IV, can also be generated in the form of command

2. For ( initialization of variables ; condition Judgment ; variable ))

Do

Loop Body

Done

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/4D/F7/wKioL1ReB82TT9u2AACvB0PJbMg479.jpg "title=" dd.png "alt=" Wkiol1reb82tt9u2aacvb0pjbmg479.jpg "/>

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/4D/F8/wKiom1ReB43xynXMAADpXB4BhC0663.jpg "title=" hu.png "alt=" Wkiom1reb43xynxmaadpxb4bhc0663.jpg "/>

This script will output1-10, these numbers, the initial variablesIto be1, the condition is judgedIless than or equalTenThe loop body is executed , the largeTenthen jump out of the loop body, once per cycle,Ivalue is automatically added to the1.

Second, while

1.while condition

Do

Loop Body

Done

Demo: Calculate the sum of all integers within 1--100:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/4D/F9/wKiom1ReDZXwYnJIAADH5aABdgM461.jpg "title=" Rrre.png "alt=" Wkiom1redzxwynjiaadh5aabdgm461.jpg "/>


650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/4D/F7/wKioL1ReDkOz8LSiAACQN7_DQGg292.jpg "title=" ee.png "alt=" Wkiol1redkoz8lsiaacqn7_dqgg292.jpg "/>


Just write it that way. Have time to go back to review 、、、

This article from the "heartbroken people in the Tianya" blog, please be sure to keep this source http://8649605.blog.51cto.com/8639605/1574453

Shell Scripting Learning (ii)

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.