If not quoted, it is a pattern match! (From the Bash man page: "Any part of the pattern may be quoted to force it to be matched as a string."). Here in Bash, the two statements yielding "yes" are pattern matching, other three are string equality:
I reckon that the handle $@ in a shell script is an array of all arguments given to the script. Is this true? I ask because I normally use search engines to gather information, but I can't google f...
Modern shells such as Bash and Zsh have inherited this construct from Ksh, but it is not part of the POSIX specification. If you're in an environment where you have to be strictly POSIX compliant, stay away from it; otherwise, it's basically down to personal preference.
When writing shell programs, we often use /bin/sh and /bin/bash. I usually use bash, but I don't know what's the difference between them. What's the main difference between Bash and sh? What do we ...
Bash always seemed backward with numeric evaluations using an operator consisting of a string (-eq) and string comparisons using a numeric operator "==" or "=" just you mess you up. If you ask me I'd say the problem is the distro swapping out bash. That is just my opinion, but this is my fix.
Related discusions: bash for loop: a range of numbers and unix.stackexchange.com - In bash, is it possible to use an integer variable in the loop control of a for loop?
The switches -a and -n are not strictly part of a bash if statement in that the if command does not process these switches. What are primaries? I call them "switches", but the bash documentation that you linked to refers to the same thing as "primaries" (probably because this is a common term used when discussing parts of a boolean expression).
Using Bash's own regex-matching operator, =~, is a faster alternative in this case, given that you're only matching a single value already stored in a variable:
Use -e . For single ' [', the bash builtin behaves the same as the test bash builtin, which behaves the same as /usr/bin/[ and /usr/bin/test (the one is a symlink to the other). Note the effect of -a depends on its position: If it's at the start, it means file exists. If it's in the middle of two expressions, it means logical and.
#!/bin/bash # To focus exclusively on the performance of each type of increment # statement, we should exclude bash performing while loops from the # performance measure.