The play says Shell programming

Source: Internet
Author: User
Tags arithmetic

The importance of the shell is self-evident to every system adminstrator. Today Allah is here to talk about the acid and cool shell programming of those years.

let's start with an entry-level programming example. By the way with the Dora of Allah's head melon seeds.

Write script/root/bin/sumspace.sh, pass two file paths as parameters to the script, calculate the sum of all the blank lines in these two files

On this topic, it is the question of two variables.

So the answer came soon.

Ignoring shebang and annotations is the following:

echo $[' cat $file 1 |grep ^$|wc-l ' + ' cat $file 2 |grep ^$|wc-l ']

Then Allah proudly copied the above code to the command line to execute.

650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M01/9D/9D/wKiom1mCy1Kwjf1PAAAXchXbIuQ128.png "wid Th= "height=" alt= "Wkiom1mcy1kwjf1paaaxchxbiuq128.png"/>

Well? The cursor is flashing. Oh, yes, forget the value of the variable! So, enter. (two files are copied in advance and placed in the self-built temporary folder.) )

650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M02/9D/9D/wKiom1mCy1PjPJBXAAAg0TiyBfw072.png "wid Th= "height=" alt= "Wkiom1mcy1pjpjbxaaag0tiybfw072.png"/>

Eh Why are you still flashing? Is it in the middle of an operation? Allah, there is no way, after all, the two files plus six hundred or seven hundred lines, just wait for you!

So, two minutes later ...

Five minutes passed.

10 minutes passed.

650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M02/9D/9D/wKiom1mCy1PjPJBXAAAg0TiyBfw072.png "wid Th= "height=" alt= "Wkiom1mcy1pjpjbxaaag0tiybfw072.png"/>

Allah will not be too slow to think that a program can be executed so long! There's something wrong with it! Since the beginning of the wildcard, Allah knows how smelly Linux's temper is.

Allah had to press CTRL + C. This is very, ah give me an error.

650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M02/9D/9D/wKiom1mCy1OS5XWhAAA0UcPqPA4654.png "wid Th= "height=" 94 "alt=" Wkiom1mcy1os5xwhaaa0ucpqpa4654.png "/>

Yhoo! syntax error. OK, I'll change it.

650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M02/9D/9D/wKioL1mCy1SDPszPAAApUFMWOSs503.png "wid Th= "height=" alt= "Wkiol1mcy1sdpszpaaapufmwoss503.png"/>

No way? All right, I'll change it.

650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M02/9D/9D/wKioL1mCy1TDMsiMAAAnUeeGTb4101.png "wid Th= "height=" alt= "Wkiol1mcy1tdmsimaaanueegtb4101.png"/>

I'll change it.

650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M00/9D/9D/wKiom1mCy1SzwkWBAAAmAz_Io6U685.png "wid Th= "height=" alt= "Wkiom1mcy1szwkwbaaamaz_io6u685.png"/>

Big Brother I was wrong. I shouldn't have a hot head, I don't want to know what to do. Me, I'll check my notes.  

Variable assignment: name= ' value '
(1) can be a direct string Varname= "root" varname= ' This is a variable '
(2) Variable reference Varname= "$USER" Varname=${user} varname= $USER
(3) Command Reference Varname= ' command ' varname=$ (command)
Variable reference: ${name} $name
"" A weak reference in which the variable reference is replaced with the value of the variable
‘‘ Strong references, where the variable references are not replaced with the variable values, while the original string is persisted

Yes, there are arithmetic operations.

To implement arithmetic operations:
(1) Let var= arithmetic expression
(2) var=$[arithmetic expression]
(3) var=$ (arithmetic expression)

(4) var=$ (expr arg1 arg2 arg3 ...) Multiply to translate *, i.e. \*

(5) declare–i var = value
(6) echo ' Arithmetic expression ' | Bc

This article is from the "RightNow" blog, make sure to keep this source http://amelie.blog.51cto.com/12850951/1953359

The play says 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.