Re: Newbie-ish question about ( [ and [[
- From: scott.oldre@xxxxxxxxx
- Date: 20 Dec 2006 05:14:50 -0800
Basics
[ ] is a bourne shell syntax and can be used in the Korn shell as
well
[[ ]] is Korn shell syntax and is reserved for string comparison
(( )) is Korn shell syntax and is reserved for numerical comparison
Examples
-- numerical comparison --
--- To test in born --
a=5
b=7
if [ $a -gt $b ] --testing to see if the value of a is greater than
the value of b
if [ $a -le $b ] --testing to see if the value of a is less than or
equal to b
-lt less than
-eq equal
-ge greater than or equal to
-ne not equal to
-- To test in korn --
if (( a > b )) --testing to see if a is greater than b
if (( a <= b)) -- testing to see if a is less than or equal to b
if (( a == b)) -- testing to see if a is exactly equal to b
The ksh can use either syntax. In some cases the script is less bulky
by using ksh syntax , at other times it's easier to use the bourne if
that's what you use for System Admin scripts most of the time.
There is a korn shell reference at http://unixinu.net/korn/quickksh.htm
look under the "if" statements just down from the top of the page.
Scott M. Oldre
Michael wrote:
I guess I'm a little dense, but I just don't get it.
When, and most importantly why do you use ( [ and [[ in shell scripts?
I'm trying to construct a simple:
if ( some-test-goes-here ) or [ some-test-goes-here ] or maybe even [[
some-test-goes-here ]]
then
blah
fi
construct and I am not sure when or why to use one of the three
different kinds of brackets.
Can someone point me to a resource?
Thanx!
.
- Follow-Ups:
- Re: Newbie-ish question about ( [ and [[
- From: Stephane CHAZELAS
- Re: Newbie-ish question about ( [ and [[
- From: Janis Papanagnou
- Re: Newbie-ish question about ( [ and [[
- References:
- Newbie-ish question about ( [ and [[
- From: Michael
- Newbie-ish question about ( [ and [[
- Prev by Date: Re: Extracting a character from a string
- Next by Date: Re: Newbie-ish question about ( [ and [[
- Previous by thread: Re: Newbie-ish question about ( [ and [[
- Next by thread: Re: Newbie-ish question about ( [ and [[
- Index(es):
Relevant Pages
|