「予期しない「完了」マーク付近の構文エラー」の問題を特定できません。

「予期しない「完了」マーク付近の構文エラー」の問題を特定できません。

「完了」マークの近くに予期しない構文エラーが発生しました。というエラーが発生し、スクリプトを特定できませんでした。私のコードは次のとおりです。

trap "rm ~/tmp/* 2> /dev/null; exit" 0 1 2 3
phonefile=~/sournce/corp_phones
looptest=y
while [ $looptest" = y ]
do
   clear
   cursor 1 4; echo "Corporate Phone List Additions"
   cursor 2 4; echo "=============================="
   cursor 4 4; echo "Phone Number: "
   cursor 5 4; echo "Last Name   : "
   cursor 6 4; echo "First Name  : "
   cursor 7 4; echo "Middle Init : "
   cursor 8 4; echo "Dept #      : "
   cursor 9 4; echo "Job Title   : "
   cursor 10 4; echo "Date Hired  :"
   cursor 12 4; echo "Add Another? (Y)es or (Q)uit "
   cursor 4 18; read phonenum
   if [ "$phonenum" = 'q' ]
      then
         clear; exit
   fi
   cursor 5 18; read lname
   cursor 6 18; read fname
   cursor 7 18; read midinit
   cursor 8 18; read deptno
   cursor 9 18; read jobtitle
   cursor 10 18; read datehired
#check to see if last name is not a blank before write to disk
   if [ "$lname" >  "        "]
      then
         echo $phonenum:$lname:$fname:$midinit:$deptno:$jobtitle:$datehired >> $phonefile
   fi
   cursor 12 33; read looptest
   if [ "$looptest" = 'q' ]
      then
        clear; exit
   fi
done

ベストアンサー1

今、3つの障害物があります。

  1. 二重引用符がない -$looptest"次のようにする必要があります。"$looptest"
  2. >比較のために"$lname" > ...- 文字列は次のようになります。if [ "$lname" != ...
  3. bash、zsh、dash、または通常のshなど、必要なシェルを使用してスクリプトを解析するように特定のshe-bang行を設定します。

ここでしばらく時間をかけてshellcheck.netサービスを呼び出します。そのボックスにコードを貼り付けると、提案と警告が表示されます。

おすすめ記事