• 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