Linux executes more than one command __linux

Source: Internet
Author: User
Early in the beginning of the basic Linux command, see this knowledge point, tell the truth feel a little wonderful. How good it is to execute a piece of work, and have to write a few commands together.

Some of the most recent projects are in the process of completing automated regression testing. By the way, it's the legendary "Automation".

Used to always use the "shell+expect" combination.


Later in the use of the process, more and more feel expect this dongdong too backward, for the following reasons: 1. The government has stopped issuing a new version of the book;

2. Debugging is inefficient, many times the path of the code to go with people think too much difference.


Then I decided to use Python as a scripting language to get it all done.

Practice has proved that Python development is very efficient, it is really "rough fast." Stop, digress ...

In my automation case, you need to check whether a command succeeds (assuming the command is Checklog, successfully returns 0, and the failure returns 1).

Normally, in the next sentence of Checklog, direct "echo $" to judge 0,1. However, because there are 0 and 1 in the command prompt in the execution environment, Pexpect cannot determine "echo $?" The results.

Later, pondering the thinking, the mind will come out of the above knowledge point, tried, and successfully solve the problem hereby mark.

# expect Checklog execution to succeed
Checklog && Echo Success
Pexpect.expect (' success ')

# expect Checklog execution to fail
Checklog | | echo Failure
Pexpect.expect (' failure ')

Revision of Knowledge points:
1. Order by semicolon ";" Delimited, these commands are executed sequentially;
2. Commands are separated by "&&", and these commands are executed sequentially, and the command to execute the error is stopped;
3. Command by double vertical Line "| |" Delimited, the commands are executed sequentially, the command to execute successfully is stopped, and all subsequent commands are not executed;

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.