Bash Expressions: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 27: Line 27:


==[[...]]==
==[[...]]==
{{External|http://mywiki.wooledge.org/BashFAQ/031}}

Revision as of 19:37, 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

[[...]]

http://mywiki.wooledge.org/BashFAQ/031