For loop with 1 2 3 4 5do echo "The value is: $loop" (double quotes and no quotes are OK, single quotes do not work, output $loop) done results:
The value is:1
The value Is:2
The value Is:3
The value Is:4
The value Is:5 http://www.cnblogs.com/dwdxdy/archive/2012/07/25/2608816.html shell reads into text arithmetic comparison by line:-GT is greater than-lt less than-eq equals-ne The-ge is not equal to or greater than-le less than or equal to-f file to detect whether the files are normal files (neither directories nor device files), and if so, returns True.
The-D file detects whether the files are directories and, if so, returns True.
The-R file detects whether the files are readable and, if so, returns True.
The-W file detects whether the files are writable and, if so, returns True.
The-X file detects whether files can be executed and, if so, returns True. If statement three formats if....fiif...else...fiif...elif...else...fi #!/bin/sh
a=10
B=20
If [$a-eq $b]
Then
echo "A is equal to B"
elif [$a-gt $b]
Then
echo "A is greater than B"
elif [$a-lt $b]
Then
echo "A is less than B"
Else
echo "None of the condition met"
Fi
Operation Result:
A is less than B #!/bin/bash
For file in ' ls '
Do
Echo $file
"Done" inside can execute Terminal command example
#!/bin/bash
Counter=0
While [$counter-lt 5]
Do
((counter++))
echo "Counter is $counter"
Done
Results:
Counter is 1
Counter is 2
Counter is 3
Counter is 4
Counter is 5 or this can also a= ' expr $a + 1 ' #加号两边有空格 Process Control: #!/bin/bash
While:
Do
Echo-n "Input a number between 1 to 5:"
Read Anum
If ["$aNum"-ge 1] && ["$aNum"-le 5]
Then
echo "Good boy!"
Else
echo "Bad man! bye! "
Break
Fi
Done function: #!/bin/bash
Hello () {
echo "Url is http://qunar.it"
}
#调用函数
Hello
Results:
URL is http://qunar.it special variable:
1.$1,$2,$3...${10},${11} ... Represents the 1th parameter, the second argument ...
2.$# indicates the number of arguments
3.$* all parameters passed to the script or function.
[email protected] All parameters passed to the script or function.
5.$? function return value #!/bin/bash
Funwithparam () {
echo "The value of the first parameter is $!"
echo "The value of the second parameter is $!"
echo "The value of the tenth parameter is $!"
echo "The value of the tenth parameter is ${10}!"
echo "The value of the eleventh parameter is ${11}!"
echo "The amount of the parameters is $#!" # Number of parameters
echo "The string of the parameters is $*!" # All arguments passed to the function
echo "The string of the parameters is [email protected]!" # All parameters passed to the function test
Return one #返回值
echo "The result value is $?!" # The fan Huizhi passed to the function
}
Funwithparam 1 2 3 4 5 6 7 8 9 34 73
echo "The return value is $?" or shell programming under Linux.
Var1=/usr/lib/abcdefg.so.bak
Var2=/usr/sbin/ifconfiggg
All_name= ' basename $var 1 '
Sub_name1= ' basename $var 1. Bak '
Sub_name2= ' basename $var 2 gg '
echo "All_name: $all _name" #all_name: Abcdefg.so.bak
echo "sub_name1: $sub _name1" #sub_name1: abcdefg.so
echo "Sub_name2: $sub _name2" #sub_name2: ifconfig
Yes, mainly using the command basename to parse file names with paths
Shell Getting Started example