LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 10-01-2015, 03:15 PM   #1
sarexpert
LQ Newbie
 
Registered: Apr 2015
Location: NJ, USA
Distribution: Ubuntu Studio
Posts: 3

Rep: Reputation: Disabled
The difference between parenthesis and brackets


The differences between [ ] [[ ]] and ( ) have been confusing to me.
() is for function headers
Corrected parentheses - thanks chrism01
(( )) as I understand it is posix and is looking for numbers # abc=6 ; if (( $abc -eq 6 )) ; then ; blah

[ ] is looking for a single logical condition # def="6" ; if [ "$def" == "6" ] ; then ; blah
[[ ]] is newer, and works in bash and will take nested logical analysis. # abc=6 ; if [[ $( $abc -eq 6 ) ]] ; then ; blah

I'm still not sure, but what I have been trying seems to have been working.

It would really be cool if someone made up a good one pager with examples.

Last edited by sarexpert; 10-09-2015 at 08:02 AM. Reason: Fixed error
 
Old 10-01-2015, 07:24 PM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 7.7 (?), Centos 8.1
Posts: 17,774

Rep: Reputation: 2537Reputation: 2537Reputation: 2537Reputation: 2537Reputation: 2537Reputation: 2537Reputation: 2537Reputation: 2537Reputation: 2537Reputation: 2537Reputation: 2537
@sarexpert:
http://www.tldp.org/LDP/abs/html/comparison-ops.html
http://www.tldp.org/LDP/abs/html/ops.html

Note that single () is for fn headers, double (( )) is for arithmetical comparisons.
[[ ]] is preferred to [] because its more robust/better behaved - see those docs.
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] How to get vim help on parenthesis matching? stf92 Linux - Software 2 01-27-2014 11:39 PM
[SOLVED] bash compound tests and parenthesis Jerry Mcguire Programming 4 03-24-2011 08:37 PM
[SOLVED] closing parenthesis script cruzdelsur Programming 5 08-30-2010 09:55 AM
vim matching parenthesis rohr Linux - Software 2 04-23-2005 05:12 PM
Can't rename file with parenthesis in name pleasehelp Linux - Newbie 4 03-16-2004 03:01 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 10:17 PM.

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