Reputation: 27604
In linux bash shell, how to subtract a variable from another in if
? I've tried the following:
#!/bin/bash
start=0
end=1
if [ end - start -eq 1 ]; then
echo "right"
fi
It doesn't work.
Upvotes: 0
Views: 4311
Reputation: 20014
Since you specifically mentioned bash, use its arithmetic support:
#!/bin/bash
start=0
end=1
if ((end - start == 1)); then
echo "right"
fi
Upvotes: 4
Reputation: 5387
Do something something like as shown below:
#!/bin/bash
start=0
end=1
if [ `expr $end - $start` -eq 1 ]; then
echo "right"
fi
Upvotes: 1