LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-12-2009, 05:37 PM   #1
RaptorX
Member
 
Registered: Jun 2009
Location: Emden, Germany
Distribution: Slackware 12.2, Slax 6.1
Posts: 254

Rep: Reputation: 37
[bash] if - then syntax question.


Hi all,

I have a question.

when you use an if statement directly in bash you have to put the ";" at the end or not? or am I mixing it with the for loop?

I am reading advance bash scripting and it shows the if - then statements without ";" so I need a little clarification here.

thanks in advance
 
Old 08-12-2009, 05:47 PM   #2
anomie
Senior Member
 
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora
Posts: 3,935
Blog Entries: 5

Rep: Reputation: Disabled
Example:
Code:
#!/bin/bash

foo='something'

if [ ${foo} == 'something' ]
then
  echo "first test passed"
fi

if [ ${foo} == 'something' ] ; then
  echo "second test passed"
fi

exit 0
Both are syntactically correct. (The second is marginally easier to read, IMO.)
 
Old 08-12-2009, 05:55 PM   #3
RaptorX
Member
 
Registered: Jun 2009
Location: Emden, Germany
Distribution: Slackware 12.2, Slax 6.1
Posts: 254

Original Poster
Rep: Reputation: 37
thanks for the ups.

so basically ";" to continue in the same line, and empty if I make a new line with "then"
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
syntax error in bash tugce_zehra Linux - Newbie 2 12-05-2008 09:59 AM
bash syntax question babag Linux - Newbie 14 05-30-2008 05:15 PM
bash syntax Sushy Programming 1 06-04-2007 06:25 PM
BASH : syntax error semaja2 Programming 6 01-26-2006 12:33 AM
explanation on some bash syntax slzckboy Programming 2 10-02-2005 06:06 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:39 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration