Homepage | Welcome visitor | Log inSign upSite MapPasser en français
Search
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012

– Sdl's –
WeeklyNews

Lite Edition, Year 2012

Vol. 19, Sat. May 19th, 2012 13:42
M C M L X X X I I :   T H I R T Y   Y E A R S   O F   P R O G R A M M I N G   A N D   T E C H N O L O G Y   D E S I G N 

BLOG
Home
Curriculum Vitæ
Résumé
Blog
IPHONE® & IPAD® DEVELOPMENT
LeKiosque™: First 3D Newsstand For IPad®
MaryChard™: Hiperf 3D & Collada
SdlImage™: 3D Graphics Booster
MOBILE/TELCOS
Mobile Web: 35M Pages/month
Mobile Earth
Mobile MMO
Wireless Multiplayer
VIDEO GAMES INDUSTRY
Nightmare Creatures 3 (Ubisoft)
Nightmare Creatures 2 (Konami)
Commando (Namco)
Angel Quest (GT Interactive)
Storm (Electronic Arts)
Asterix & Books (Canal Plus)
CONSULTING
Consulting & M&A
Business
iPAD 3D NEWSSTAND
SINCE 2010
MOBILE WEB
2009
CONSULTING M&A
2007
MOBILE EARTH
2006
MOBILE MMO
2005
WIRELESS MULTIPLAYER
2004
VIDEO GAMES INDUSTRY
1994-2003
BEFORE
<1994

The True Story of Unix Shell 'IF'

Jan. 28th, 2009 13:16 by sdelucaPermalink | TrackBack: http://stephanedeluca.com/trackback/858 | del.icio.us logoDel.icio.us — exists for 3 years & 3 months ago — Rate:  — — Sorry, this content is not available in english.

I came across an issue with one of my server script while I was giving it a refresh this morning. The script is a backup script that lays on every single box of my cluster which purpose is to make the backup of each box in regards of each individual box role in the cluster.

So I which to (pseudo) code the following:


thisbox = gethostname

if thisbox is a front server then do backup front files

if thisbox is a back server then do backup databases


Which I too much quickly translated in shell script as follows:


HOST=`hostname -s`

if [$HOST=='ns6511']
then
# do somthing
fi


And guess what? you're right, it doesn't work. Shell complains as follows (HOST contains 'ns651' on this box):


/home/mobiluck/backup/mlo.backup.sh: line 28: [ns6511: command not found

It simply shocked me in the very first seconds I read this report, but quickly felt as Newton did with his "Eureka".

What you might consider as a pure sheel syntax -- the square brackets -- is not actually! So what's this?

[ is a linux command -- I mean an executable file which you can see by doing this on your own box:


# l /usr/bin/[
-rwxr-xr-x 1 root root 29K aoû 28 11:59 /usr/bin/[

Alright, [ is a command. So what? Why the hell my script fails?

It fails because I forgot to put blanks between the command and the arguments! Hence the command it though I was interested in was [ns6511.

In fact $HOST, ==, ns6511, ] are the options of [ command.

So insert all missing blanks between the command and its options and all will work as expected.

Finally the correct syntax is obviously as follows:


HOST=`hostname -s`

if [ $HOST == 'ns6511' ]
then
# do somthing
fi


Hope this reminder pleased you and this learning session just proves something important: how Unix -- which, at first sight, could be considered as a deprecated technology of the 70s -- is really not. The answer is probably: simplicity.

And simplicity here means power and evolution.

Leave a comment | Reddit!

Comments

Be the first to leave a comment.
Leave a comment No HTML tags allowed — Textile syntax appreciated




  Inform me when an answer is posted

Want to insert a photograph into your comment?
To insert a photo in your comment do the following:
1 — Choose one by clicking on Choose File button and select an image.
2 — Insert the special tag [image] in your text where you want it to appear.
3 — Validate your comment by cliking on the button.





If you have difficulties to read the code, click on the image.

Textile

A Humane Web Text Generator

what does it do?

Quick block modifiers:
Header: hn.
Blockquote: bq.
Footnote: fnn.
Numeric list: #
Bulleted list: *

Quick phrase modifiers:
_emphasis_
*strong*
??citation??
-deleted text-
+inserted text+
^superscript^
~subscript~
%span%

To apply attributes:
(class)
(#id)
{style}
[language]

To align blocks:
< right
> left
= center
<> justify

To insert a table:
|a|table|row|
|a|table|row|

To insert a link:
"linktext":url

To insert an image:
!imageurl!

To define an acronym:
ABC(Always Be Closing)

To reference a footnote:
[n]

Putting it all together

View sample input text


Advanced Features

<iphone src="url"/> : Display an iPhone Web application

<youtube src="url"/> : Display an YouTube video

<member username/> : Display an iPhone Web application

<iphone src="url"/> : Display an iPhone Web application

Smileys
[angry] :
[asleep] :
[clap] :
[cold] :
[cry] :
[dollars] :
[gift] :
[guru] :
[iloveyou] :
[laugh] :
[lol] :
[loving] :
[music] :
[shuss] :
[sick] :
[smile] :
[sport] :
[sweat] :
[unhappy] :
[wink] :
Copyright © 1994 ˜ 2012 dsei.biz / Stéphane de Luca — All Rights Reserved | 01:42 PM RSS RSS Feed  | Best viewed with Apple logo Safari