LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   The difference between parenthesis and brackets (https://www.linuxquestions.org/questions/linux-software-2/the-difference-between-parenthesis-and-brackets-4175555098/)

sarexpert 10-01-2015 03:15 PM

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.

chrism01 10-01-2015 07:24 PM

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


All times are GMT -5. The time now is 01:43 PM.