Thursday, October 9, 2014

Bash Params

Bash utils:

File tests

This section probably holds the most tests, I'll list them in some logical order. Since Bash 4.1, all tests related to permissions respect ACLs, if the underlying filesystem/OS supports them.
Operator syntaxDescription
-a True if exists. :!: (not recommended, may collide with -a for AND, see below)
-e True if exists.
-f True, if exists and is a regular file.
-d True, if exists and is a directory.
-c True, if exists and is a character special file.
-b True, if exists and is a block special file.
-p True, if exists and is a named pipe (FIFO).
-S True, if exists and is a socket file.
-L True, if exists and is a symbolic link.
-h True, if exists and is a symbolic link.
-g True, if exists and has sgid bit set.
-u True, if exists and has suid bit set.
-r True, if exists and is readable.
-w True, if exists and is writable.
-x True, if exists and is executable.
-s True, if exists and has size bigger than 0 (not empty).
-t True, if file descriptor is open and refers to a terminal.
-nt True, if is newer than (mtime). :!:
-ot True, if is older than (mtime). :!:
-ef True, if is a hardlink to . :!:

String tests

Operator syntaxDescription
-z True, if is empty.
-n True, if is not empty (this is the default operation).
= True, if the strings are equal.
!= True, if the strings are not equal.
< True if sorts before lexicographically (pure ASCII, not current locale!). Remember to escape! Use \<
> True if sorts after lexicographically (pure ASCII, not current locale!). Remember to escape! Use \>

Arithmetic tests

Operator syntaxDescription
-eq True, if the integers are equal.
-ne True, if the integers are NOT equal.
-le True, if the first integer is less than or equal second one.
-ge True, if the first integer is greater than or equal second one.
-lt True, if the first integer is less than second one.
-gt True, if the first integer is greater than second one.

Misc syntax

Operator syntax Description
-a True, if and are true (AND). Note that -a also may be used as a file test (see above)
-o True, if either or is true (OR).
! True, if is false (NOT).
( ) Group a test (for precedence). Attention: In normal shell-usage, the "(" and ")" must be escaped; use "\(" and "\)"!
-o True, if the shell option is set.
-v True if the variable has been set. Use var[n] for array elements.
-R True if the variable has been set and is a nameref variable (since 4.3-alpha)


Copied from here

No comments:

Post a Comment