2017-03-10 19 views
1
ここ

次のコードです:私は実行していたときにファイルエラーの予期せぬ終了を取得

compact()  { echo "compact alarms" } 

node() { echo "node alarms" } 

severity() { echo "Severity alarms" } 

csv() { echo "CSV generator" } 

table() { echo "tabular data" } 

help() { echo "help" } 

exit() { echo "exit" } 

while getopts ":c :n :s :x :t :h :e" opt; do 
    case $opt in 
      c) compact 
       ;; 
      n) node 
       ;; 
      s) severity 
       ;; 
      x) csv 
       ;; 
      t) table 
       ;; 
      h) help 
       ;; 
      e) exit 
       ;; 
      *) 
       echo "Error wrong Syntax,Opening help" && help 
       ;; 
     esac 
done 

のsh test.sh -t NEWFILEを私は構文エラーに test.shを取得しています:行36:構文エラー:予期しないファイルの終わり 予期しないファイルの終わりが表示されている理由を教えてもらえますか?

答えて

1

あなたは代わりにこれを試してくださいonelinersを使用するように、機能のために間違った構文を使用している:

help() { echo "help";} 

exit() { echo "exit";} 

説明

bashmanからページ:

Shell Function Definitions

A shell function is an object that is called like a simple command and executes a compound command with a new set of positional parameters. Shell functions are declared as follows:

[ function ] name() compound-command [redirection] 

Compound Commands

{ list; } list is simply executed in the current shell environment. list must be terminated with a newline or semicolon. This is known as a group command.

+0

ありがとうございました。 –

関連する問題