Linux--shift command-shell function-shell script Combat

Source: Internet
Author: User
Tags mysql automatic backup

• Execute an error after importing scripts from Windows into a Linux system
shift parameter Left SHIFT command
How to use functions in shell
shell script Combat: MySQL automatic backup and automatic decompression zip file script

Error after importing script from Windows to Linux system
Linux and Windows line break issues
Using the Dos2unix tool
Dos2unix Filename
==============================================================================
Shift: Parameter left SHIFT command:
Each time, the parameter sequence moves left one position, $ #的值减1, used to process each parameter separately, remove the parameter, no longer available
eg:shift.sh
#!/bin/bash

Until [-Z "$"]
Do
echo "[Email protected]"
Shift
Done
Execution results
[Email protected] scripts]#./shift.sh 1 2 3 4 5 6 7 8 9 0
1 2 3 4 5 6 7 8 9 0
2 3 4 5 6 7 8 9 0
3 4 5 6 7 8 9 0
4 5 6 7 8 9 0
5 6 7 8 9 0
6 7 8) 9 0
7 8 9 0
8 9 0
9 0
0


====================================================================================
How to use functions in the shell
Function: to encapsulate a function and invoke the name of a functor directly when used.
Advantages: modularity, code readability

Definition of a function
Grammar:
Function name ()
{
Command sequence
}

Or
Function name () #function可以不写
{
Command sequence
}

Note: When a function is called: without ()

Call Syntax:
Function Name parameter 1 parameter 2 ....

Variables in the function are global variables, no local variables
When calling a function, you can pass arguments, and use $1,$2 ... to reference the passed arguments in the function.

Xargs command
Role: Construct a list of parameters and run commands

The difference between Xargs and exec:
1:exec comparison criteria, attribute find one parameter
2: Processing large files, multi-file time is not the same
Xargs Tasks for multiple files

Exec is processed once per object
Xargs: A batch of processing





Scripting Exercises:
1: Automatically back up MySQL database
2: Unzip zip automatically


Linux--shift command-shell function-shell script Combat

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.