Test statements for Linux shell scripts

Source: Internet
Author: User
Tags error code file size

In the shell script to do a variety of tests frequently, test the format of the statement:

(1) Test < test expression >

(2) [< test expression;

(3) [[< test expression "]]

Three kinds of differences, in the third can be a wildcard matching, and &&,| |,<,>, the operator can also be normal presence in [[]], but cannot exist in [].

File test operator

"Inode, save the file's meta information, such as file creator, file modification time, creation time, file size, etc., is the inode, Chinese is the index node, view the Inode method: Stat filename"

String operator and integer two-dollar comparison operator

When it comes to numerical calculation, try to use (()), in (()) to refer to the value of the variable, plus $ or not all can, in (()) Do not use the left and right spaces

Classification of Shell variables:

A read-only environment variable, (personally understood, is the execution of a variable submitted to a shell script through bash).

parameter variables and process state variables

Process state variable usage, command, script will return a status code,

Common error code, 1 generic error, 126----script does not execute permission 127 command not found.

echo $$-----PID for the current process

echo $? The return value of a command or script that was executed before-----

Echo $! -----The PID of the last job running in the background

echo $_ The last parameter of a command or script that was executed before-----

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.