Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Test on file types question

Status
Not open for further replies.

pjb

Programmer
May 1, 2001
148
US
I get inconsistent results when running a file test command with single brackets:

if [ -s <filename> ]


When I use double brackets, it works:

if [[ -s <filename> ]]


What is the difference?
 
Hi:

From the Solaris 7 man page:

A conditional expression is used with the [[ compound
command to test attributes of files and to compare strings. Word splitting and file name generation are not performed on the words between [[ and ]]. Each expression can be constructed from one or more of the following unary or binary expressions:


-a file True, if file exists.
.
.
-s file True, if file exists and has size greater than zero.
# unquote

The [ is a replacment for test. The following
fragments are equivalent:

if [ $x -lt $y ]; then

if test $x -lt $y ; then

Regards,

Ed



 
[[ is an extension introduced in the Korn shell, so if you are using the Bourne shell it won't work.

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top