Bash

意外標記“完成”附近的 BASH 語法錯誤

  • September 9, 2021

這裡有什麼問題?我在“完成”附近遇到錯誤。

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"

這應該有效:

#!/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=...並在[[ ... ]].

引用自:https://unix.stackexchange.com/questions/668020