When do you use (( )) or /usr/bin/test?

To answer your question: you want to use /usr/bin/test when you don't trust the test builtin of the shell you are using, or when you have to test something, but do not want to invoke a shell for it. 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.

See here for the definition. There you can also see that is defined as an alias for test. A subtle difference 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 the builtin version is that it eliminates the context switches between the shell and the test executable. 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 (apart from the performance advantage of the builtin).

If you are interested in the details about the differences of the POSIX test and some shell builtin test (and some debian internal politics) then you can read this discussion. There, some debian developers argue whether they should use the system test or the builtin test, because of some differences in the implementation of the builtin 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 $(( )). See here for the definition. $(( )) can also do arithmetic, but has some differences in the overall behaviour.

The following links explain these topics in great detail: mywiki.wooledge.org/BashFAQ/031 (difference between test, and ) mywiki.wooledge.org/ArithmeticExpression (let, (( )) and $(( ))) ibm.com/developerworks/library/l-bash-te... (all of the above).

(( )) evaluates an arithmetic expression in bash (see man bash). Evaluates a logic expression in bash (see man bash). Is the same as test, used to check file types and compare values (see man test).

You use /usr/bin/test when you want things to run more slowly. Modern shells (most shells released since about 1990, probably earlier) have test and its synonym as built-in commands. Formally invoking /usr/bin/test would be an act of desparation because the shell has a broken test command and the system standalone is OK - but it would be better to get a fixed shell.

You use (( ... )) to do arithmetic. The old-fashioned alternative was the expr command. That was tricky to use because it required a lot of escaping - it is/was a separate executable, and you had to get lots of shell metacharacters past the shell to expr.

Hence: x=$(expr $y '*' $z) instead of ((x = y * z)) You don't even have to decorate the variables with $ in (( ... )).

Bash: double or single bracket, parentheses, curly braces has a very good set of answers to all things bash & brackets.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions