Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 981963
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:37:29+00:00 2026-05-16T04:37:29+00:00

I looked at bash man page and the [[ says it uses Conditional Expressions.

  • 0

I looked at bash man page and the [[ says it uses Conditional Expressions. Then I looked at Conditional Expressions section and it lists the same operators as test (and [).

So I wonder, what is the difference between [ and [[ in Bash?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T04:37:29+00:00Added an answer on May 16, 2026 at 4:37 am

    [[ is bash’s improvement to the [ command. It has several enhancements that make it a better choice if you write scripts that target bash. My favorites are:

    1. It is a syntactical feature of the shell, so it has some special behavior that [ doesn’t have. You no longer have to quote variables like mad because [[ handles empty strings and strings with whitespace more intuitively. For example, with [ you have to write

      if [ -f "$file" ]
      

      to correctly handle empty strings or file names with spaces in them. With [[ the quotes are unnecessary:

      if [[ -f $file ]]
      
    2. Because it is a syntactical feature, it lets you use && and || operators for boolean tests and < and > for string comparisons. [ cannot do this because it is a regular command and &&, ||, <, and > are not passed to regular commands as command-line arguments.

    3. It has a wonderful =~ operator for doing regular expression matches. With [ you might write

      if [ "$answer" = y -o "$answer" = yes ]
      

      With [[ you can write this as

      if [[ $answer =~ ^y(es)?$ ]]
      

      It even lets you access the captured groups which it stores in BASH_REMATCH. For instance, ${BASH_REMATCH[1]} would be “es” if you typed a full “yes” above.

    4. You get pattern matching aka globbing for free. Maybe you’re less strict about how to type yes. Maybe you’re okay if the user types y-anything. Got you covered:

      if [[ $ANSWER = y* ]]
      

    Keep in mind that it is a bash extension, so if you are writing sh-compatible scripts then you need to stick with [. Make sure you have the #!/bin/bash shebang line for your script if you use double brackets.

    See also

    • Bash FAQ – “What is the difference between test, [ and [[ ?”
    • Bash Practices – Bash Tests
    • Server Fault – What is the difference between double and single brackets in bash?
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The man page for Bash says, regarding the -c option: -c string If the
Before you bash me for duplicate, please know that I have looked nearly every
I wonder if anyone can help with this? I have a bash script. It
I'm rather new to bash and a few others, and I have looked online
I have a bash script that uses bash's read builtin to obtain a username
I looked through Stackoverflow and found almost identical question here . It was asked
I looked through other questions and couldn't find what I needed. Best if I
I looked around but haven't found an answer to this. I have a CentOS
I looked around and couldn't find it! Maybe I didn't look hard enough,but this
I looked at this: Returning values from nested functions in Javascript but it did

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.