How can I use a simple one-line test and execute multiple commands if the test is true? The following does not work:
for f in $source_dir/*.mov
do
[ ! -f "$f" ] && echo "No files in source directory. Exiting."; break || continue
# a bunch of commands
done
I got it to work using the below code, but I feel like there should be as simpler way.
for f in $source_dir/*.mov
do
if [ ! -f "$f" ]; then
echo "No files in source directory. Exiting."
break
else
# a bunch of commands
fi
done
Use {
:
[[ ! -f "$f" ]] && { this; that; break; } || { the_other; ...; }
Whether that's "simpler" or not is a question of aesthetics.
Using [[
instead of [
is optional. But it's usually better.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments