这里有什么问题吗?我在接近“完成”时遇到错误。
echo " Writing a program to print even numbers by adding 1 if the number is odd."
for i in {1..10}
do
d=$(($i % 2))
if [[$d = 1]]
then
$iq=$(($i+1))
echo "$iq"
done
echo "end"
答案1
这应该有效:
#!/bin/bash -
echo " Writing a program to print even numbers by adding 1 if the number is odd."
for i in {1..10}
do
d=$(($i % 2))
if [[ $d -eq 1 ]]
then
iq=$(($i+1))
echo "$iq"
fi
done
echo "end"
插入 a fi
,删除$
from$iq=...
并在 内添加空格[[ ... ]]
。