2017-11-22 17 views
0

私は現在、selectループ内でcase文を使用しているbashプログラミングを行っています。しかし、入力を行うたびに、コントロールはデフォルトのcaseになります。たとえば。私は日付を入力すると、日付の場合に行くのではなく、デフォルトの場合に移動します。あなたの誰かが何らかのエラーに気付くことができますか?selectループ内でのcase文の使用

#!/bin/bash 
    select command in date pwd ls 
    do 
    case $command in 
     date)date;; 
     pwd)pwd;; 
     ls)ls;; 
     *)echo"wrong";; 

    esac 
    done 
+1

:交換するには、 'エコー "間違った"'と '' "間違った" エコー。 – Cyrus

+0

あなたのコードはうまく動作します。 – Cyrus

答えて

1

[...]私は、日付を入力すると、代わりに日付ケースに行こうと、それはケースをデフォルトになります。

select組み込み番号は、番号付きオプションで使用できます。最初のオプション "date"には1を入力し、2番目のオプション "pwd"には2を入力する必要があります。 help selectから

関連部品:ところで

select: select NAME [in WORDS ... ;] do COMMANDS; done 
    [...] If the line consists of the number 
    corresponding to one of the displayed words, then NAME is set 
    to that word. If the line is empty, WORDS and the prompt are 
    redisplayed. If EOF is read, the command completes. Any other 
    value read causes NAME to be set to null. [...] 
関連する問題