A. Character test
= =: Test for equality, equality is true, not equal to False
! =: Test Whether it is unequal, not equal to true, etc as false
>
<
-N String: Tests whether the specified string is empty, empty is true, or false
-Z String: Tests whether the specified string is not empty, is not empty, and the null is False
[$username = = $useername 1] There must be spaces at both ends of the equals sign
1.bc
echo "SCALE=2;111/22;" | BC calculates two number of reserved two decimal places
Exercise: Write a script
Pass a parameter (single-character on line) to the script, such as Q, Q, quit, or quit, to exit the script, otherwise, the user's parameters are displayed;
#!/bin/bash
#
if [$ = ' Q '];then
echo "Quiting ..."
Exit 1
elif [$ = ' Q '];then
echo "Quiting ..."
Exit 2
elif [$ = ' Quit '];then
echo "Quiting ..."
Exit 3
elif [$ = ' Quit '];then
echo "Quiting ..."
Exit 4
Else
echo $
Fi
2.for Cycle
For I in {1...10}; Do
Addition operation
Done
Write a script:
Calculates the sum of all odd and all and all even numbers within 100, respectively, showing the
#/bin/bash
#
Declare-i oddsum=0
Declare-i evensum=0
Declare-i s
For I in {1..100};d o
Let s=$[$I%2]
If [$s-eq 0];then
Let oddsum=$[$oddsum + $I]
elif [$s-eq 1];then
Let evensum=$[$evensum + $I]
Fi
Done
Echo ${oddsum}---${evensum}
Combination test conditions
-A: With relation
-O: or relationship
!: Non-relational
If [$#-gt 1-a $#-le 3]
If [$#-gt 1] && [$#-le 3]
This article is from "Luo Chen's blog" blog, please be sure to keep this source http://luochen2015.blog.51cto.com/9772274/1637233
Shell Programming---Character testing and for loops