There are two ways to represent logic in bash:
(1) [$state = = "Running"-a $name = = "Zone1"]
(2) [[$state = = "Running" && $name = = "Zone1"]]
The second type is supported in Ksh.
Instance:
#! /bin/-P "pelease input your name:"-P "pleaase Input your password:" passwdif [$name = = "Root"-a $passwd = = "123" ]; Then "Login successful! "Else " Login failed! "fiif [[$name = =" Root "&& $passwd = =" 123 " ]]; Then "Login Pass"else "login fail"fi
Output Result:
Pelease Input your Name:root
Pleaase Input your password:123
Login Successful!
Login Pass
The use of read-p in Ksh seems to be problematic and will appear./learn_shell.save[2]: Read:no query process, such an error message.
So change to the following form:
(1) The first kind
echo "ThePrompt\c"
read TheSomthing
echo $TheSomething
(2) The second type
read TheSomething?‘ThePrompt‘
The subtle difference is that the first type of prompt is followed by a carriage return, and the second does not enter.
Instance:
#! /usr/bin/"Pelease Input your Name:"read Nameread passwd? " Pleaase Input your password: "if [[$name = =" Root "&& $passwd = =" 123 " ]]; Then "Login Pass"else "login fail"fi #. /learn_shell.save pelease Input your name: (This place has a carriage return)123Login Pass
Two representations of logic and in shell