LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-21-2011, 08:14 PM   #1
ust
Senior Member
 
Registered: Mar 2003
Location: fasdf
Distribution: Debian / Suse /RHEL
Posts: 1,130

Rep: Reputation: 30
What is the use of it


I have a script like below .

if [ ] ;

then
else

fi


I just would like to know what is the use of ; sign , I tried if omit it , the result is the same , then what is the use of it ? would it make difference if add it to the program ?

Thanks.
 
Old 11-21-2011, 08:25 PM   #2
dive
Senior Member
 
Registered: Aug 2003
Location: UK
Distribution: Slackware
Posts: 3,232

Rep: Reputation: 299Reputation: 299Reputation: 299
You usually put a semi-colon when joining two or more commands on the same line. So you could also write it like this:

Code:
if [ ]; then
  (do something)
else
  (do something else)
fi
 
Old 11-21-2011, 08:38 PM   #3
fingers99
Member
 
Registered: Nov 2011
Location: Liverpool UK
Distribution: Debian, Knoppix, Kanotix
Posts: 63

Rep: Reputation: Disabled
Try

Code:
if []; then
else
fi
and then

Code:
if [] then
else
fi
See the difference? AFAIK/remember, it's "just" a line seperator. Years since I did shell scripting, but the stuff on steve-parker.org looks good.
 
Old 11-21-2011, 08:49 PM   #4
jimtony
Member
 
Registered: Jan 2011
Location: Shanghai,China
Distribution: fedora
Posts: 73
Blog Entries: 1

Rep: Reputation: 2
It is the grammar of the bash shell.Just remember it is OK.
 
Old 11-22-2011, 08:50 AM   #5
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721
Also, note that the [] isn't part of the shell's syntax. It's an alias for the "test" command, which is used for comparing values.

You can insert any command instead of the [].
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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




All times are GMT -5. The time now is 09:17 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration