|
| cool Statistics |
| | coolcommands: | 1338 | | Categories: | 83 | | Total queries: | 620333 | | Members: | 22813 | |
|
|
|
 |
|
|
Search coolcommands.com
 |
Submitted by:
lvo   |
coolcommand
how to use the test command to check files and variables |
Description
The test command allows you to test files and variables in your shell scripts:
# test expression
OR
[ expression ]
Flags for file testing:
-r : True if file exists and is readable -w : True if file exists and is writable -x : True if file exists and is executable -f : True if file exists and is a regular file -d : True if file exists and is a directory -c : True if file exists and is a character special file -b : True if file exists and is a block special file -p : True if file exists and is a named pipe (FIFO) -u : True if file exists and is a SETUID file -g : True if file exists and is a SETGID file -k : True if file exists and the sticky bit is set -s : True if file exists and has a size greater than zero
Logical expressions:
! : Not -a : And -o : Or (has lower precedence that -a) \( \) : Parentheses for grouping
Relational operators:
-ne : Not equal -eq : Equal -gt : Greater then -ge : Greater than or equal -le : Less than or equal -lt : Less than
Strings comparison:
-z str : True if string length is zero -n str : True if string length is non-zero str1 = str2 : True if strings are identical. NOte that this uses a single = symbol unlike C's equality operator. str1 != str2 : True if strings are not identical str : True if string is not the null string
Examples:
if [ ! -r $1 ] then echo File $1 does not exist or is not readable exit fi
for i in * do if [ -d $i ] then echo $i fi done
[ $VERBOSE -eq 1 ] && echo "This is verbose output"
|
Example
test expression |
Return to search results
 |  |  |  |
Random coolcommands
coolcommand: insmod - to install loadable kernel modules in linux
Example: insmod ipchains
[show me the details] |
coolcommand: metaclear - how to forcibly clear all metadevices in Solaris Volume Manager
Example: metaclear -a -f
[show me the details] |
coolcommand: mppUtil - how to use the RDAC (MPP) utility to display information for all arrays connected
Example: mppUtil -a
[show me the details] |
coolcommand: rrdtool - read data from a rrdtool (round robin database) database file
Example: rrdtool fetch cpu.rrd AVERAGE -r 900 -s -1h
[show me the details] |
|
|
coolcommands.com - the search engine for UNIX sysadmins :: unix commands and scripts
|  |  |  |  |
|
|
|
|
 |
|
|
|
Top 5 Submitters
|
|---|
| lvo | 1160 |
| audet | 37 |
| kah00na | 32 |
| Mariom | 24 |
| lebjf000 | 14 |
Top 5 Searches
|
| Category Solaris | 51966 |
| Category AIX | 49058 |
| Category General UNIX | 47582 |
| solaris | 23554 |
| aix | 22739 |
|
|
|
|