Bash Expressions: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
No edit summary
Line 3: Line 3:
* [[bash#Subjects|bash]]
* [[bash#Subjects|bash]]


=Difference between <tt>-a</tt> and <tt>&&</tt>=
=Conditional Expressions=
 
==Difference between <tt>-a</tt> and <tt>&&</tt>==


If want to combine the results of multiple command executions in an <tt>if</tt> condition, use <tt>&&</tt>, not <tt>-a</tt>.
If want to combine the results of multiple command executions in an <tt>if</tt> condition, use <tt>&&</tt>, not <tt>-a</tt>.

Revision as of 23:30, 4 September 2016

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