Two representations of logic and in shell

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.