Shell First Knowledge

Source: Internet
Author: User

1. Basic Shell Syntax: (Hello,shell)

#!/bin/bashecho"Hello,shell! "

The results of the operation are conceivable: Console output:Hello,shell

2.Shell variable definitions and references:

#!/bin/Bashvalue="hello,shell"echo $value

Running Result: Hello,shell

Problems: In the definition of variables must be aware of ' = ' can not have spaces on both sides, accustomed to the code of the students generally in the definition of variables when the subconscious will be written

" Hello,shell! "

However, in a shell script, this assignment is wrong and results in an execution error:Value:command not found

You can see the reference variable by adding the $ identifier to the front of the variable and implementing a reference to the variable.

3. About #!/bin/bash:

#! means to use the script interpreter to interpret the script, followed by the path of the selected script interpreter/bin/bash

4.Shell Reference Parameters

#打印给定目录下的某些文件, the first parameter indicates the directory where the file resides, and the remaining parameters are the file names to be printed. #!/bin/bashdir=$1shift  for file inch [email protected]      do        Cat $file     Done

As you can see, the reference parameter is selected by $1-10, and the shell supports a maximum of 1-10 readable parameters, but the shift appears to allow the shell to accept more arguments:

The shift command shifts the parameter to the left and, if there are 12 arguments, can represent a maximum of $1-$10

When you perform shift:

The $1-$10 that can be represented is the parameter 2-11

Similarly, if you continue with shift 5

Then only $1-$6 represents the parameter 6-12

If you continue with shift 7

Parameter back to 1 = parameter 1

So shift can extend the length of the shell parameters, as well as the flexibility to use external parameters.

#利用for循环将当前目录下的. c files are moved to the specified directory and sorted by file size, displaying the contents of the specified directory after the move. #!/bin/forfilein 'ls -1grep  '. *.c"'      #从目录下选择出. c file {      mv /shell/$ file/shell/shellb              #将所选出的. c Files Move to the Shellb folder by              the ls -ls/root/b        

Learning Summary: Shell script learning must be done more practice, do more, to find some exercises to practice, in the course of practice exercises to learn shell usage, find some classic script to learn.

Shell First Knowledge

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.