-1

Made a script that requests user's correct password (qwerty) comparing a hash in text file. Referencing the script I then have to make a portfolio of items to choose from in other folders that load upon selecting 1-7 and 8 for exit. Have tried a lot given my comments but cannot get it working. Thanks.

#!/bin/bash

#ReadMe=`cat PasswordCheck.sh`
#echo "$ReadMe"
# https://stackoverflow.com/questions/7427262/how-to-read-a-file-into-a-variable-in-shell

#value=$(<PasswordCheck.sh)
#echo "$value"

bash PasswordCheck.sh
# https://stackoverflow.com/questions/13567947/run-bash-commands-from-txt-file

#read -sp 'PasswordCheck.sh'

Val_A="1. Create a folder"
Val_B="2. Copy a folder"
Val_C="3. Set a password"
Val_D="4. Calculator"
    Val_E="5. Create Week Folders"
    Val_F="6. Check Filenames"
    Val_G="7. Download a File"
    Val_H="8. Exit"

    #read -sp 'UserPassword : ' Pass_Var 

    #PwdChk='PasswordCheck.sh'

#if read exit O "PasswordCheck.sh" exit 0 "$SecretHashedPassword"; then
if read "qwerty"; then
    echo "1. Create a folder
    2. Copy a folder
    3. Set a password
    4. Calculator
    5. Create Week Folders
    6. Check Filenames
    7. Download a File
    8. Exit"
    exit 0

else
    echo "Goodbye"
    exit 1

fi
#case $Val_A in
    #9) echo "Create a folder selected";;
    #8|pork) echo "IDK...";;
    #*) echo "Please select a response from numbers 1-4.";;
#esac
    #"2. Copy a folder"
    #"3. Set a password"
    #exit 0

#https://www.linkedin.com/learning/search?entityType=VIDEO&keywords=bash%20case&u=2072140

#if ["$Val_A" -eq "1"]; then
#bash Foldermaker.sh

#if read "1"; then

#fi

exit 0
RHayabusa
  • 1
  • 3
  • 1
    This might help: [How to debug a bash script?](http://unix.stackexchange.com/q/155551/74329) – Cyrus Jun 11 '20 at 08:51
  • I'll be honest, I don't think you'll get a satistying answer as your question stands. Problems include : 2 questions into one (the authentication and the menu selection should be considered separately), a lot of noise in your script (is the commented code relevant? Or the urls? better clean that up), a call to a PasswordCheck.sh we know nothing about, misconceptions about basic tools of the language (`if read "qwerty"` won't do what its english meaning would suggest). Following a bash tutorial would help a lot to ask a better question, but at least split it in two parts and clean the code – Aaron Jun 11 '20 at 09:02

1 Answers1

0

The password checking part of your script remains fuzzy to me, however I might be able to help you with the menu question.
Select might be what you need to get the menu of choices set up.
Below is a sceleton script that you can extend according to your needs:

#!/bin/bash
function menu() {
        options=("Create_a_folder" "Copy_a_folder" "Set_a_password" "Calculator" "Create_Week_Folders" "Check_Filenames" "Download_a_File" "exit")
        echo "Choose option:" 1>&2
        select opt in ${options[@]}; do
        case ${REPLY} in
                *) choice="${options[$(( $REPLY - 1 ))]}"; break;;
        esac
        done
        echo "$choice"
}

#passwordcheck=`somefunction`
passwordcheck=true    # replace this once your function is ready
if [ "$passwordcheck" == "true" ]; then
        choice=`menu`
        [[ "$choice" == "exit" ]] && exit
        echo "You have chosen: $choice"
fi
lab9
  • 596
  • 2
  • 8