Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 264
  • Last Modified:

Differences of [ ] and [[ ]] test in bash script

Hello, I would like to understand on which scenario we use [ ] and [[ ]]. What is the the difference between these test operator. Please provide some example to understand it better. Thanks a lot!
0
beer9
Asked:
beer9
2 Solutions
 
nemws1Commented:
There's a long description of here it:

  http://mywiki.wooledge.org/BashFAQ/031

Basically, if you have a script with [ as its testing operand, it'll work in bash, sh, ksh, and several other shells.  [[ is more bash specific, but it allows for more fun things (like using "&&" to mean "and" instead of the older style "-a")
0
 
farzanjCommented:
[ ] is the old way, compatible with old Born.  The newer one is [[ ]] in both Bash and Korn.  With this you can use C++ style operators like ==, <=, &&, || instead of -eq, -le, -a, -o etc and you don't need to use quotations around a variable name.

For mathematical operations, you should use (( )) pair instead.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now