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

  • Home
  • SEARCH
  • 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 6083985
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:28:04+00:00 2026-05-23T11:28:04+00:00

I have seen scripts using the test command and [ ] or [[ ]]

  • 0

I have seen scripts using the test command and [ ] or [[ ]]. But when do we need to use /usr/bin/test and (( ))?

Are there any occasions when we need to go for the latter?

Regards,
John

  • 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-23T11:28:04+00:00Added an answer on May 23, 2026 at 11:28 am

    To answer your question:

    • you want to use /usr/bin/test when you want to test something but not in a shell (for example find ... -exec test ...)
    • you want to use (( )) when you have an arithmetic expression to solve, AND you are using bash, because (( )) is bash specific.

    Now for some background:

    The command /usr/bin/test is required by the POSIX standard. POSIX also requires that [ is defined as an alias for test. The only difference between test and [ is that [ requires the final parameter to be a ].

    Since test is used so frequently in shell scripts, most shells have a builtin version of test (and [). The advantage of a builtin is that it avoids context switches. Which, depending how you use test in your script, can be a measurable performance advantage.

    I think it is safe to assume that under most circumstances it doesn’t matter whether you use the system test or the shell’s builtin test. But if you want to use test in a find -exec situation then of course you have to use the system test because find cannot use the shell test.

    (( )) and [[ ]] were introduced by bash (and perhaps some other shells) as syntactic sugar. (( )) evaluates arithmetic expressions, while [[ ]] evaluates logical expressions. Both allow you to write the expressions in a "more natural syntax".

    The decision to use [[ or [ depends on whether you want to use the "more natural syntax", and, since sh does not support [[, whether you want to depend on bash.

    The decision to use (( )) depends on whether you need arithmetic expressions, and again, since sh does not support (( )), whether you want to depend on bash. The POSIX alternative to (( )) is $(( )). Note that there are some subtle differences in the behaviour.

    The following links explain these topics in great detail:

    • http://mywiki.wooledge.org/BashFAQ/031 (difference between test, [ and [[)
    • http://mywiki.wooledge.org/ArithmeticExpression (let, (( )) and $(( )))
    • http://www.ibm.com/developerworks/library/l-bash-test/index.html (all of the above)

    See also:

    • POSIX definition of test
    • POSIX definition of $(( ))

    Bonus: Some debian developers once argued whether they should use the system test or the shell builtin test, because of some differences in the implementation of the builtin test. If you are interested in details of the differences of the system test and the shell builtin test then you can read the debian developer discussion here: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=267142.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have Googled for it but there are no ready scripts - as opposed
I have seen examples of printing from a windows application but I have not
I have seen the official demos on lwjgl.org but I would like to see
I have been trying to create rotating object using jQuery and without any other
I have seen some examples of php scripts that read email headers and parse
I have seen scripts that have a menu fixed to the top of the
I wonder how I can manipulate the DOM tree using PHP? I have seen
Hy There I'v seen alot of admob topics on stackO, but unfortunutaly not for
I have a basic username textbox. This textbox can be seen here: http://68.71.136.106/test.htm In
I've seen a lot of scripts for daemonizing a python script in linux, but

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.