Note that there are some explanatory texts on larger screens.

plurals
  1. POif statement issue and grep issue in shell script of unix??
    primarykey
    data
    text
    <p>Why is it that in my script, there are no outputs when I run it? What is the problem in my if and grep ?? Thank you.</p> <p>Here is my script,</p> <pre><code>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 </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload