How do I ignore the division by zero error in Bash?
Example 1: (Doesn't work)
echo $((1/0)); echo "yay";
echo $((1/0)) || echo "yay";
Example 2:
echo -n $(echo -n $((1/0))) 2> /dev/null; echo "yay";
Is there an easier way than example 2, that would default to a specific value, when a division by zero is encountered.
man bash
: "Evaluation is done in fixed-width integers with no check for overflow, though division by 0 is trapped and flagged as an error." But this trap seems to be bash-internal. – Nils Dec 31 '11 at 21:47