coolcommands.com - the search engine for unix sysadmins :: unix commands and scripts
Friday May 24, 2013


 Home
 Search
 Advanced Search
 Category Search
 Affiliates
 Acknowledgements
 Cool Links

Username

Password

Remember me
Forgot your password?

Who's Online
We have 74 guests online

Newest Member

nbewwmbxog

Hit Counter
11567820 Visitors

cool Statistics
coolcommands:1338
Categories:83
Total queries:620333
Members:22813





Search coolcommands.com
Search Keyword:


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



FREE
myPMS

Password
Management
System

by

LVOware.com




Top 5 Submitters

lvo1160
audet37
kah00na32
Mariom24
lebjf00014

Top 5 Searches

Category Solaris51966
Category AIX49058
Category General UNIX47582
solaris23554
aix22739

Terms of Use
Privacy
Contact


 
coolcommands.com © 2013. All Right Reserved.
Programming by PRATTICO Consulting . Hosting by Apricusum