What's the difference, if any, in the following two bash evaluations:
if [[ -s $file1 && $file1 -nt $file2 ]]; then
if [[ -s $file1 ]] && [[ $file1 -nt $file2 ]]; then
There is no difference. They're functionally identical.
An interesting aside, if you used [
instead of [[
, there actually is a detectable difference cause by the order of evaluation:
[ -s "$file1" -a "$file1" -nt "$(echo side effect >&2)" ]
[ -s "$file1" ] && [ "$file1" -nt "$(echo side effect >&2)" ]
In this case, the first line would print "side effect" while the second would not.
Again, however, this is only the case for [
and not for [[ ]]
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With