Test switches and special parameters in shell scripts

Source: Internet
Author: User
Tags bit set switches

1. Test Switch

Some test instructions are included in the shell, and the following table lists the meanings of these test instructions and whether they are available for the test command, bash, Ksh.

Switch

Test

Bash

Ksh

Defined

-A FILE Support Support Just the file exists.
-B FILE Support Support Support File exists and is a block file like a disk device such as/dev
-C FILE Support Support Support File exists and is a character file like a TTY device such as/dev
-D FILE Support Support Support File exists and is a standard directory
-E FILE Support Support Support Just the file exists.
-F FILE Support Support Support The file exists and is a standard file similar to a flat file
-G FILE Support Support Support The file exists and is a set-group-id. This refers to a file license that changes the user's effective group for file enforceability
-G FILE Support Support Support The file exists, and its group ownership is the user's valid group ID
-H FILE Support Support Support The file exists, and it is a symbolic link. Same as-l
-K FILE Support Support Support The file exists, and it is glued to a bit set. This means that only the owner of the file or the owner of the directory can delete the file
-L STRING Support and a numeric value similar to/usr/bin/test-l STRING-GT 5 && Echo, comparing string lengths
-L FILE Support Support Support The file exists, and it is a symbolic link. As with-h
-N STRING Support Support Support The length of the STRING is nonzero
-N FILE Support Support File exists, but has been modified since the most recent read-in
-O OPTION Support Support Support If the OPTION of the shell is opened, returns True, such as Set-x
-O FILE Support Support Support The file exists and its owner is determined by a valid user ID
-P FILE Support Support Support File exists, and it is a named pipe (or FIFO)
-R FILE Support Support Support File exists and is readable
-S FILE Support Support Support File exists, and its size is greater than 0 bytes
-S FILE Support Support Support File exists, and it is a socket
-T [FD] Support Support Support Open FD (file descriptor) in a terminal, default is stdout
-U FILE Support Support Support The file exists and Set-user-id is set
-W FILE Support Support Support File exists, and can be written
-X FILE Support Support Support File exists and is executable
-Z STRING Support Support Support The length of the STRING is 0

2. Special Parameters

The special parameters in the shell are the internal variables of the shell, which are to be used with the prefix $.

Like echo $? is to get the value of the shell internal variable "?".

List of content variables:

Parameters

Defined

* From 1 onwards, complete the list of all positional variables. If a double quotation mark is quoted, the word that becomes the first character of the IFS (internal file delimiter) value is divided
@ From 1 onwards, complete the list of all positional variables. If double quotes are quoted, each positional parameter becomes a single word
# Number of positional parameters in decimal
? The return code of the last or most recent foreground task. If the task is killed by a signal, the return value is 128 plus the value of the signal. For example: The standard kill signal value is 15, then the return value is 143
- All flags sent to the shell, or flags provided by the SET command
$ Shell process ID. If it is in a child shell, it is extended to the value of the current shell, not the child shell.
! Process ID of the command that was recently put into the background execution
_ Expands to the last parameter of the previous command
0 Extended to the name of a shell or shell script
1 ... 9 The positional parameters provided to the shell, function, or script. A value larger than 9 can be accessed using ${number}

Test switches and special parameters in shell scripts

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.