Bash Expressions: Difference between revisions
Jump to navigation
Jump to search
Line 31: | Line 31: | ||
[ and "test" are equivalent. [[ is a keyword rather than a program. [ and [[ have much in common and share many expression operators like "-f", "-s", "-n", and "-z". | [ and "test" are equivalent. [[ is a keyword rather than a program. [ and [[ have much in common and share many expression operators like "-f", "-s", "-n", and "-z". | ||
A notable difference is that [[ allows =~ and regular expression matching. |
Revision as of 19:56, 20 February 2018
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
[[...]]
[ and "test" are equivalent. [[ is a keyword rather than a program. [ and [[ have much in common and share many expression operators like "-f", "-s", "-n", and "-z".
A notable difference is that [[ allows =~ and regular expression matching.