May you help me with the correct syntax of the follow bash statements please
X=10
if [[ "$X" <= 5 ]]; then
echo "The value is between 1 and 5"
for ((i=1;i<=${X})); do
echo $i
done
else if [[ "$X" > "5" && "$X"<= 10 ]]; then
echo "The value is between 6 and 10"
for ((i=1;i<=${X})); do
echo $i
done
else if [[ "$X" > 10 )) && "$X" <= 20]; then
echo "The value is between 10 and 20"
for ((i=1;i<=${X})); do
echo $i
done
fi
I receive syntax errors. I've tried both ways, like in my first post and using comparison operators as you suggest me.
X=10
if [[ "$X" -le 5 ]]; then
echo "The value is between 1 and 5"
for ((i=1;i<=${X})); do
echo $i
done
else if [[ "$X" -gt 5 && "$X" -le 10 ]]; then
echo "The value is between 6 and 10"
for ((i=1;i<=${X})); do
echo $i
done
else if [[ "$X" -gt 10 && "$X" -le 20 ]]; then
echo "The value is between 10 and 20"
for ((i=1;i<=${X})); do
echo $i
done
fi
But I continue receiving syntax errors
-syntax error near of unexpected element "fi"
Even when I had some other errors, that's was the main problem.
The correct syntax as I want is:
X=17
if (( "$X" <= 5 )); then
echo "The value is between 1 and 5"
for ((i=1;i<=${X};i++)); do
echo $i
done
elif (( "$X" > 5 )) && (( "$X" <= 10 )); then
echo "The value is between 6 and 10"
for ((i=1;i<=${X};i++)); do
echo $i
done
elif (( "$X" > 10 && "$X" <= 20 )); then
echo "The value is between 10 and 20"
for ((i=1;i<=${X};i++)); do
echo $i
done
fi