How do I replace AND (&&) in a for loop?

The equivalent to your original sequence would be:

for i in {1..20}
do
   cmd $i || break
done

The difference with Amit's answer is the script won't exit, i.e. will execute potential commands that might follow the sequence/loop. Note that the return status of the whole loop will always be true with my suggestion, this might be fixed if relevant in your case.


If you want a dirty one-line solution, you can create a command and send it to bash.

echo "cmd "{1..20}" &&" : | bash

You can break out of the loop if one of them failed

for i in {1..55}; do
    if ! cmd $i; then
        exit 1
    fi
done