Sponsored Content
Full Discussion: Birthday Calculation
Top Forums Shell Programming and Scripting Birthday Calculation Post 302272417 by methyl on Tuesday 30th of December 2008 02:01:38 PM
Old 12-30-2008
I agree with fpmurphy. [[ ]] is supported in Posix and required though I personally have only found it useful in the context of "while [[ condition ]]".

[[ and ]] are keywords with strict syntax rules. A keyword starts a command and should not be used in the wrong context or be quoted (or you can get unpredictable results).

[ and ] are commands. (On early unix they were executables).

More importantly.
What goes between [[ and ]] is a "conditional expression" with one set of syntax.
What goes between [ and ] is a simple "test" with a simpler syntax. See "man test" where it you'll see that [ ] is an equivalent to "test".

The two syntaxes are covered in the man page for a Posix shell. As it happens some of the basic syntax is common between the two types of condition giving the (wrong) impression that the syntax is always interchangable.

The big syntax difference is with boolean expressions.


BTW. fpmurphy script gives syntax errors with both Posix sh and ksh because the substring variables are from bash. I'm not convinced that the line starting "if [[" will give the right result either (not tested).
 

4 More Discussions You Might Find Interesting

1. News, Links, Events and Announcements

Happy birthday Linux

Linux has turned 10 . Happy birthday and congrats to the hackers whose labor pains keep giving us new tarballs. (From /. ) (1 Reply)
Discussion started by: mib
1 Replies

2. What is on Your Mind?

UNIX 40th Birthday

A little off topic, as far as not being a critical help issue, but I have been searching about for the OFFICIAL date that is considered the 40th Birthday of UNIX. Some folks mentioned it in March, I think do to a mention on Slashdot of the 40th birthday being this year, but I thought I recall... (1 Reply)
Discussion started by: scotbuff
1 Replies

3. Linux

Happy Birthday Linux :)

The Linux kernel was originally created by Linus Torvalds, a Finnish computer science student, and first announced to the world on August 25, 1991-exactly 20 years ago today. At the time, Torvalds described his work as a "hobby" and contended that it would not be "big and professional" like the GNU... (2 Replies)
Discussion started by: itkamaraj
2 Replies

4. What is on Your Mind?

Happy birthday Neo

Wish you many many happy returns of the day, stay blessed. (1 Reply)
Discussion started by: Akshay Hegde
1 Replies
while(n)						       Tcl Built-In Commands							  while(n)

__________________________________________________________________________________________________________________________________________________

NAME
while - Execute script repeatedly as long as a condition is met SYNOPSIS
while test body _________________________________________________________________ DESCRIPTION
The while command evaluates test as an expression (in the same way that expr evaluates its argument). The value of the expression must a proper boolean value; if it is a true value then body is executed by passing it to the Tcl interpreter. Once body has been executed then test is evaluated again, and the process repeats until eventually test evaluates to a false boolean value. Continue commands may be exe- cuted inside body to terminate the current iteration of the loop, and break commands may be executed inside body to cause immediate termi- nation of the while command. The while command always returns an empty string. Note: test should almost always be enclosed in braces. If not, variable substitutions will be made before the while command starts execut- ing, which means that variable changes made by the loop body will not be considered in the expression. This is likely to result in an infinite loop. If test is enclosed in braces, variable substitutions are delayed until the expression is evaluated (before each loop iter- ation), so changes in the variables will be visible. For an example, try the following script with and without the braces around $x<10: set x 0 while {$x<10} { puts "x is $x" incr x } SEE ALSO
break(n), continue(n), for(n), foreach(n) KEYWORDS
boolean value, loop, test, while Tcl while(n)
All times are GMT -4. The time now is 03:18 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy