RHCE Study Notes ($)-Shell

Source: Internet
Author: User

The shell script's reference book from the foundation to the advanced can find hundreds of, the beans here for the entire study note integrity, or audacity the most basic grammar review again. The most basic include variables, comparisons, operators, conditional statements, and loop statements.


Variables are divided into local variables, environment variables, position variables


First look at local variables, variable name = value of the way to assign values, but only in the current shell is valid


For example, there's no way to recognize a child shell.

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/59/6F/wKiom1TS2-LBiMuOAACnDDyQ0_s513.jpg "style=" float: none; "title=" 1.PNG "alt=" Wkiom1ts2-lbimuoaacnddyq0_s513.jpg "/>


Environment variables can be configured by means of export, so that the child shell can also identify

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/59/6C/wKioL1TS3M7wPUJjAACUzkDW6OQ153.jpg "style=" float: none; "title=" 2.PNG "alt=" Wkiol1ts3m7wpujjaacuzkdw6oq153.jpg "/>


However, the above configuration is only temporary, reboot will be gone.

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/59/6F/wKiom1TS2-Oh5QqdAABUdG3YZLk742.jpg "style=" float: none; "title=" 3.PNG "alt=" Wkiom1ts2-oh5qqdaabudg3yzlk742.jpg "/>


Can be permanently enforced by modifying the configuration file. When you log in to your home directory, these hidden files are automatically loaded in your home directory.

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/59/6C/wKioL1TS3M_joWvrAADJBcYZH-o396.jpg "style=" float: none; "title=" 4.PNG "alt=" Wkiol1ts3m_jowvraadjbcyzh-o396.jpg "/>

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/59/6F/wKiom1TS2-Tg1y2nAAA9mcNdcYo969.jpg "style=" float: none; "title=" 5.PNG "alt=" Wkiom1ts2-tg1y2naaa9mcndcyo969.jpg "/>


The above is only valid for the current user, and if all users are active, you can modify the/ETC/BASHRC file.


The order in which these files are loaded is as follows.

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/59/6C/wKioL1TS3NDjvGV1AAMsw3OzJJk592.jpg "style=" float: none; "title=" 6.PNG "alt=" Wkiol1ts3ndjvgv1aamsw3ozjjk592.jpg "/>


There are already pre-configured environment variables in the shell, such as

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/59/6F/wKiom1TS2-WhKT-qAACB2nTbV6Y611.jpg "style=" float: none; "title=" 7.PNG "alt=" Wkiom1ts2-whkt-qaacb2ntbv6y611.jpg "/>


Can be modified as needed, such as I need the prompt to display the entire path, you can modify the $PS1 variable

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/59/6C/wKioL1TS3NHwrtjvAABpXtUt7RM407.jpg "style=" float: none; "title=" 8.PNG "alt=" Wkiol1ts3nhwrtjvaabpxtut7rm407.jpg "/>


In addition, there are variables for location, such as $1,$2, which represent the first position and the second position, respectively. If it's 10, bracket it.


I can also use $# to count all the variables, $* output all the variables


650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/59/6F/wKiom1TS2-WS0xnXAAB2YGYAynw423.jpg "style=" float: none; "title=" 9.PNG "alt=" Wkiom1ts2-ws0xnxaab2ygyaynw423.jpg "/>


Example: Output the value of the first position (the name of the program itself) second position (actually the first parameter)

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/59/6C/wKioL1TS3NLzV4TPAAC8_0cBWM4738.jpg "style=" float: none; "title=" 10.PNG "alt=" Wkiol1ts3nlzv4tpaac8_0cbwm4738.jpg "/>


Note Differences in output, single quotes, double quotes, and anti-quotes


650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/59/6F/wKiom1TS2-fzRTYuAAEUTeXDcqw513.jpg "style=" float: none; "title=" 11.PNG "alt=" Wkiom1ts2-fzrtyuaaeutexdcqw513.jpg "/>


There are some predefined variables that have special meanings, $? Represents the return value of the last command, 0 indicates success, and the other number indicates a failure


650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/59/6C/wKioL1TS3NSARB__AAB2q0twcos364.jpg "style=" float: none; "title=" 12.PNG "alt=" Wkiol1ts3nsarb__aab2q0twcos364.jpg "/>

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/59/6F/wKiom1TS2-mwO_uCAAA8QIXi2_A543.jpg "style=" float: none; "title=" 13.PNG "alt=" Wkiom1ts2-mwo_ucaaa8qixi2_a543.jpg "/>


Comparison of the main can be the number, character comparison; note this and many other languages are reversed,-eq,-GT and the like are compared to the number;==,< instead of the character.


650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/59/6C/wKioL1TS3NaSYrWAAAB5W25KxZ4599.jpg "style=" float: none; "title=" 14.PNG "alt=" Wkiol1ts3nasyrwaaab5w25kxz4599.jpg "/>


In addition to this, you can determine whether a file or directory exists.

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/59/6C/wKioL1TS3NeTq3EoAAB-ELVub64970.jpg "style=" float: none; "title=" 15.PNG "alt=" Wkiol1ts3netq3eoaab-elvub64970.jpg "/>



For numeric operations, it can be manipulated by declare, (()), let, and BC. However, only BC can perform floating-point operations, and others are integer operations.

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/59/6F/wKiom1TS2-zDs_n-AACKoMGHOUE000.jpg "style=" float: none; "title=" 16.PNG "alt=" Wkiom1ts2-zds_n-aackomghoue000.jpg "/>

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/59/6C/wKioL1TS3NnQX0WYAAArV9fpyJ0043.jpg "style=" float: none; "title=" 17.PNG "alt=" Wkiol1ts3nnqx0wyaaarv9fpyj0043.jpg "/>

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/59/6F/wKiom1TS2-6yyLXvAABqTRARW5Q867.jpg "style=" float: none; "title=" 18.PNG "alt=" Wkiom1ts2-6yylxvaabqtrarw5q867.jpg "/>


Conditional judgment statements generally have two if: else or the form of a case.


such as determining whether a user name exists

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/59/6C/wKioL1TS3N_D9t6ZAAEeMEHX8Ds780.jpg "style=" float: none; "title=" 19.PNG "alt=" Wkiol1ts3n_d9t6zaaeemehx8ds780.jpg "/>


Judging by case

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/59/6F/wKiom1TS2_qh4sWmAACZe15oGzA396.jpg "style=" float: none; "title=" 20.PNG "alt=" Wkiom1ts2_qh4swmaacze15ogza396.jpg "/>

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/59/6C/wKioL1TS3OjilTBGAAC3bFxhrqA471.jpg "style=" float: none; "title=" 21.PNG "alt=" Wkiol1ts3ojiltbgaac3bfxhrqa471.jpg "/>



Loops compare common while and for


From 1 to 10, for example.

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/59/6F/wKiom1TS2_2ChZYZAABzO38UpAM853.jpg "style=" float: none; "title=" 22.PNG "alt=" Wkiom1ts2_2chzyzaabzo38upam853.jpg "/>


Can read a file or screen input via read


such as the output passwd content

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/59/6C/wKioL1TS3OrymwXQAACReBeoAnE907.jpg "style=" float: none; "title=" 23.PNG "alt=" Wkiol1ts3orymwxqaacrebeoane907.jpg "/>

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/59/6F/wKiom1TS3APBqg16AAGC5Ec1Lgk104.jpg "style=" float: none; "title=" 24.PNG "alt=" Wkiom1ts3apbqg16aagc5ec1lgk104.jpg "/>


Similarly, read test.txt content, create a user


650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/59/6F/wKiom1TS3AuybWFoAAHiIxFqWBI985.jpg "style=" float: none; "title=" 25.PNG "alt=" Wkiom1ts3auybwfoaahiixfqwbi985.jpg "/>

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/59/6C/wKioL1TS3PiQPbUqAAA5qdixPuY450.jpg "style=" float: none; "title=" 26.PNG "alt=" Wkiol1ts3piqpbuqaaa5qdixpuy450.jpg "/>


If you want to interrupt the loop, you can use break;

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/59/6F/wKiom1TS3A7BEU1lAAB4Yv8-qa0670.jpg "style=" float: none; "title=" 27.PNG "alt=" Wkiom1ts3a7beu1laab4yv8-qa0670.jpg "/>

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/59/6F/wKiom1TS3A-z2yaQAAAl2ue_0YU804.jpg "style=" float: none; "title=" 28.PNG "alt=" Wkiom1ts3a-z2yaqaaal2ue_0yu804.jpg "/>


The For loop is also very simple, such as outputting a multiplication table

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/59/6C/wKioL1TS3PuxF2E_AABRo5mGPIY400.jpg "style=" float: none; "title=" 29.PNG "alt=" Wkiol1ts3puxf2e_aabro5mgpiy400.jpg "/>

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/59/6F/wKiom1TS3BHDLdK5AACkjz8pI5E750.jpg "style=" float: none; "title=" 30.PNG "alt=" Wkiom1ts3bhdldk5aackjz8pi5e750.jpg "/>




This article is from the "Mapo Tofu" blog, please be sure to keep this source http://beanxyz.blog.51cto.com/5570417/1611830

RHCE Study Notes ($)-Shell

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.