予期しないEOFと構文エラー

予期しないEOFと構文エラー

現在、3番目のシェルスクリプトを作成していますが、問題が発生しました。これはこれまで私のスクリプトです。

#!/bin/bash
echo "choose one of the following options : \
  1) display all current users \
  2) list all files \
  3) show calendar \
  4) exit script"

while read  
do  
 case in  
        1) who;;  
        2) ls -a;;  
        3) cal;;  
        4) exit;;  
 esac    
done

スクリプトを実行しようとすると、次のように表示されます。

line2 : unexpected EOF while looking for matching '"'  
line14 : syntax error: unexpected end of file.    

私は何が間違っていましたか?

ベストアンサー1

忘れないでくださいselect

choices=( 
    "display all current users" 
    "list all files" 
    "show calendar" 
    "exit script"
)
PS3="your choice: "
select choice in "${choices[@]}"; do
    case $choice in
        "${choices[0]}") who;;
        "${choices[1]}") ls -a;;
        "${choices[2]}") cal;;
        "${choices[3]}") break;;
    esac
done

おすすめ記事