First line: #!/bin/bash--#! Interpreter for Tag script
Script: #!/bin/bash
echo "Hello World"
Give execute permission chmod +x./test.sh
Execute script:./test.sh
The $ symbol is not required when defining a variable: td= ' Date ' +%y%m%d '
1. There can be no spaces between the variable name and the symbol
2. The first character must be a letter
3. The middle cannot have the space, can use the dash (_)
4. Punctuation and keywords in bash are not available
In addition to displaying assignments, you can also use statements to assign values directly to variables
For file in ' ls/etc ' to loop the file name in/etc directory
With a defined variable, just precede the variable name with the $ symbol to echo $TD or Echo ${TD}
The same variable name can be assigned two times eg:td= ' date ' +%m%d "'
Read-only variable: readonly defines variable as read-only variable, variable value cannot be changed
Url= "Http://www.baidu.com"
ReadOnly URL
Url= "http://www.tx.com"--Error
Delete variable: unset variable_nae, cannot delete read-only variable
Shell has three variables: ① local variable: defined in script or command, only valid in current script
② environment variables: All programs are valid
③shell variables: Variables set by shell programs, with local and environment
A single quote string cannot have a variable, cannot do character escaping, and double quotation marks can be implemented.
Your_name= "World"
Stitching string greeting= "Hello,${your_name}!"
get string length ${#greeting}
extract 1-4 of the string, subscript starting from 0 ${#greeting: 1:4}
Find string $ (expr index "${greeting}" world)
Reverse quotation marks for command substitution: td= ' date ' +%y%m%d ' ' Equals $ (date "+%y%m%d")
./test.sh 1 2 3
File name executed: +---/test.sh
The first parameter is:--1
The second parameter is: $2
The third parameter is: $3-+
The number of parameters is: $#-3
The current process that the script runs id:$$-->8010
Show all parameters passed: $*-->1 2 3
$* and [email protected] Difference: $* equivalent to "1 2 3", equivalent to pass a parameter, [email protected] equivalent to "1" "2" "3" equivalent to pass three parameters
Variable_name
Learn the shell script