Linux Shell Rookie Learning notes ....

Source: Internet
Author: User
Tags echo command logical operators

20171123 Linux Shell Basics Learning Notes
1. The beginning of the shell
Generally #!/bin/bash through the #! To uniquely specify the shell path to use
The other # all represents comments.
2. Shell variables
Define variables directly with variablename= value it is possible that there is no space between the variable name and the equals sign.
The use of a variable when it is ${vairablename} is done using curly braces can have no, but recommended.
can use
The for file in ' ls/etc/' way to loop through the filename.
Use do-done to loop through the process.
#!/bin/bash
For file in ' ls/etc ';d o
Echo ${file}
Done
3. Variable can be set to read-only variable readonly variablename
Unset can delete variables.
4. The shell becomes the parameter part
$ = The first parameter $# represents the number of arguments $$ represents the ID of the current process? Indicates whether there is an exception when exiting.
5. The concept of an array inside the shell:
Inside the shell, the array is represented by ().
Arrayname= (A B C D)
Note: Arrayname equals sign and brackets cannot have spaces between them.
The subscript of the array starts with 0
{arrayname[@]} or * can iterate through all the array elements
{#arrayname [*]} can return the number of elements of an array.

6. Methods of operations in the shell.
Operations that are not supported in bash need to be done in the form of awk or expr.
Val= ' Expr 2 + 2 '
Echo $val
Note that multiplication needs to be represented by adding a backslash \*
Use an inverted quotation mark instead of a single quotation mark.

7. Comparison method
$a-eq $b this way.
-eq-ne-ge-le-gt-lt
Boolean operator
! Non-arithmetic-o or operation-A and operation
logical operators
&& Logic and | | Logical OR

File Test Operators
-B is a block device
-C is a character device
-D Whether it is a directory
-F is a normal file
-R file is readable
-W file is writable
-X file is executable
-S file is empty
-e file is present

8. Where the shell is prone to error when writing:
If using [] to represent the BOOL budget section
Where-e what needs to have a space difference
If and polygons first increase then finally increase fi cannot be absent.

9. Echo command.
echo for string output
echo "" or display string without double quotes
Echo-e "" In the content to escape
Echo ' As-is output does not get the variable not escaped
Echo ' date ' displays command execution results
echo > FileName Locate the result to a file
Echo >>filename added to the last line of the file
Read something reads the data as the value of the variable something

Some of the content of printf.
The biggest advantage over Echo is the ability to format the output string.
printf "%-10s%-8s%-4s\n" name sex weight kg
The escape character uses a backslash.

One by one. The process in the shell is controlled by:::::::::::::-:.:::----
1)
If [-e $filename]
Then
Echo # do something
elif []
Then
Do something
Else
Do something
Fi
2) for Loop
For some in many
Do
Do something
Done

3) while through bad
while (())
Do
Let i++ # for example
Done

4) until the bad
Util (())
Do
Done

Jump out of the loop using break
Continue to recycle using continue

Functions in 12.shell
function func ()
or the func () command
Can have a return statement pass after the function has finished executing the $? To get the return value.
When calling a function with Python
Not the same does not need to add () remember the following.

13.
Command description
Command > file redirects the output to file.
Command < file redirects the input to file.
Command >> file redirects the output to file in an append manner.
n > file redirects the file descriptor n files to filename.
n >> files redirect files with file descriptor N as an append to file.
N >& m merges the output file m and N.
N <& m merges the input file m and N.
<< tag will start to tag the contents of tags between tag and end tag as input.

14. The file contains
Source or come straight to the point.

Linux Shell Rookie Learning notes ....

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.