0

スクリプトを実行しても出力がないのはなぜですか? 私のifとgrepの問題は何ですか?? ありがとうございました。

ここに私のスクリプトがあります、

userfile=~/casestudies/login_users

clear

echo "      Password Recovery      "

  echo "============================="

  echo "Username: " ; read user 

  cuser=`grep $user $login_users | cut -d':' -f1`

     if [ "$cuser" = "$user" ]
         then 
              echo "Then choose a question to answer below"
              echo "(A) What is your 5th favorite color? "
              echo "(B) What is your favorite food? "
              echo "(C) What is the name of your pet? "
              echo "(D) What is the middle name of your mother's maiden name? "
              echo "(E) What is the model number of your laptop/monitor? "
              echo "choice : "         
         else
              echo "Invalid choice. Choose another."
     fi         
              read question || continue
              case $question in
                   [Aa]) echo "answer in question A: " ; read A
                      if [[ "$A" == $(grep $A userfile | tr ':' ' ') ]]  #A is the answer of the user in question A, it is stored in the login_users 
                        then      
                             echo "Correct, your password is: " 
                             echo 
                             grep $passwd $userfile | tr ':' ' '   #passwd is the original password of the user, it is stored in login_users
                        else
                             echo "Incorrect. Choose another question to answer." ;
                      fi ;;                  
                   [Bb]) echo "answer in question B: " ; read B
                      if [[ "$B" == $(grep $B userfile | tr ':' ' ') ]]  #B is the answer of the user in question A, it is stored in the login_users 
                        then      
                             echo "Correct, your password is: " 
                             echo 
                                             grep $passwd $userfile | tr ':' ' '   #passwd is the original password of the user, it is stored in login_users
                        else
                             echo "Incorrect. Choose another question to answer." ;
                      fi ;; 
                   [Cc]) echo "answer in question C: " ; read C
                      if [[ "$C"== $(grep $C userfile | tr ':' ' ') ]]  #C is the answer of the user in question A, it is stored in the login_users 
                        then      
                             echo "Correct, your password is: " 
                             echo 
                             grep $passwd $userfile | tr ':' ' '   #passwd is the original password of the user, it is stored in login_users
                        else
                             echo "Incorrect. Choose another question to answer." ;
                      fi ;;                    
                   [Dd]) echo "answer in question D: " ; read D
                      if [[ "$D"== $(grep $D userfile | tr ':' ' ') ]]  #D is the answer of the user in question A, it is stored in the login_users 
                        then      
                             echo "Correct, your password is: " 
                             echo 
                             grep $passwd $userfile | tr ':' ' '   #passwd is the original password of the user, it is stored in login_users
                        else
                             echo "Incorrect. Choose another question to answer." ;
                      fi ;;                   
                   [Ee]) echo "answer in question E: " ; read E
                      if [[ "$E"== $(grep $E userfile | tr ':' ' ') ]]  #E is the answer of the user in question A, it is stored in the login_users 
                        then      
                             echo "Correct, your password is: " 
                             echo 
                                             grep $passwd $userfile | tr ':' ' '   #passwd is the original password of the user, it is stored in login_users
                        else
                             echo "Incorrect. Choose another question to answer." ;
                      fi ;;                
              esac                 
4

1 に答える 1

0
grep $user $login_users 

割り当てられていない変数 $login_users を探しています。あなたが使いたかった

grep $user $userfile

宣言されていない変数をシェル スクリプトで使用するのは非常に簡単です。多くの場合、エラーはまったく表示されません。

于 2012-02-01T03:30:52.013 に答える