Birthday Calculation


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Birthday Calculation
# 8  
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.
# 9  
Old 01-01-2009
Thanks for the help, I didnt realise it was that simple. I had a really bad cold when I was trying to work it out Smilie
# 10  
Old 01-01-2009
Well, the original poster did not say the solution had to be "strict POSIX compliance" so much of the discussion below is academic at best.
# 11  
Old 01-01-2009
Quote:
Originally Posted by cfajohnson
[indent]
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.
This is correct, POSIX does not require the implementation of [[ ]]

The only required reserved words are:

Code:
!
{
}
case
do
done
elif
else
esac
fi
for
if
in
then
until
while

There is a white paper on the Open Group website which states:

Quote:
The four words: function, select, [[ and ]] are reserved and cannot be used where a reserved word would be recognised, such as a command name.
However this is at odds with the wording of the actual specification.
Login or Register to Ask a Question

Previous Thread | Next Thread

4 More Discussions You Might Find Interesting

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

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

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

4. 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
Login or Register to Ask a Question