Furthermore, when you use bash -c, behavior is different than if you run an executable shell script, because in the latter case the argument with index 0 is the shell command used to invoke it.
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:
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?
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 ...
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?
#!/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.
A bash function has no line numbers related to the FILE that contains the definition. NOW: The code is stored somewhere internally in the running instance of Bash - does it REALLY require a genius to actually tell which of the lines INSIDE that function cased an error?