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

Please reread the section of the POSIX specification that was posted. It says that a POSIX shell may implement [[, but it is not required to. Therefore there is no guarantee that a POSIX shell will support it, and indeed there are POSIX-compliant shells that do not support it.

For those shells that do support it, POSIX says absolutely nothing about what it should do. That's what "unspecified results" means. It could legitimately do anything at all, including wipe your hard drive.
Quote:

[[ and ]] are keywords with strict syntax rules.

Their rules are specified only by the shells that implement them.
Quote:

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).

[ is a command that is builtin to all modern shells, and on all POSIX systems, it also an executable. It is synonymous with test, which is also both a builtin and an executable.

] is not a command.
Quote:

More importantly.
What goes between [[ and ]] is a "conditional expression" with one set of syntax.

And that syntax is specified only by the shells that implement it; it is not defined in the POSIX specs.
Quote:
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".

Better than [i]man test[/t], which will tell you what the executable supports, your shell documentation will tell you what the builtin command supports: on bash, help test.
The two syntaxes are covered in the man page for a Posix shell.

Yes, they are covered in the shell's documenation only; in the POSIX specs the behaviour of [[ ]] is unspecified.

For a POSIX shell that does not support [[ ]], see /bin/sh on *BSD systems or ash or dash on Linux.
 

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
All times are GMT -4. The time now is 07:14 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy