Bash Expressions: Difference between revisions
Jump to navigation
Jump to search
Line 38: | Line 38: | ||
This is a systematic comparison of the [[...]]'s feature compared with [...]: | This is a systematic comparison of the [[...]]'s feature compared with [...]: | ||
{| | |||
|| topleft || topmiddle || topright | |||
|- | |||
| middleleft || middlemiddle || middleright | |||
|- | |||
| bottomleft || bottommiddle || bottomright | |||
|} | |||
=((...))= | =((...))= |
Revision as of 18:23, 5 February 2019
Internal
Conditional Expressions
Difference between -a and &&
If want to combine the results of multiple command executions in an if condition, use &&, not -a.
Example:
if grep "something" /file1.txt && grep "something" /file2.txt' then # "something" exists in both files ... fi
-a should be used in test expressions:
if [ -f /file.txt -a -x /file.txt ]; then ... fi
[[...]] Extended Test Command
[ and "test" are equivalent: [...] is part of the shell built-in command test. [[ is a keyword rather than a program, and it is called the extended test command. [ and [[ have much in common and share many expression operators like "-f", "-s", "-n", and "-z".
Notable differences:
- [[ allows =~ and regular expression matching.
- Variables do not have to be quoted inside [[...]] because [[ handles empty strings or strings with spaces more intuitively.
- < and > can be used for string comparison.
This is a systematic comparison of the [[...]]'s feature compared with [...]:
topleft | topmiddle | topright |
middleleft | middlemiddle | middleright |
bottomleft | bottommiddle | bottomright |
((...))
The double parentheses construct.