To Chubler XL

#!/bin/sh

touch fileuseranswer

echo "**********WELCOME TO GROUCHO MARX UNIVERSITY**********"

echo Username:

read i

echo Password:

read j

Username="${i}:{j}"

if ( ! grep -q $Username /$HOME/PhaseTest/userinfo )

then

echo "Wrong Login/Passwd"

exit 2

fi

echo

echo -e " \c"

date

QFILE=./questions

# max questions

max=$(sed 's/^[1-8][0-8]*\. /#&/' ${QFILE} | nawk -v FS="\n" -v RS="#" 'END {print NR}')

question(){

clear

sed 's/^[1-8][0-8]*\. /#&/' ${QFILE} | awk -v FS="\n" -v RS="#" -v VAR="$1" '(NR==VAR){print$0}' | tee q.tmp

#sed -n '/^'`echo "$1"`'\./,/^d) /p' ${QFILE}

while :

do

echo "Enter your choice :"

read b

if ( ! grep "$b"')' q.tmp >/dev/null ) ; then

echo "Invalid choice"

rm q.tmp

RC=1 ; break

else

rm q.tmp

grep -v ^$1 fileuseranswer >fileuseranswer.tmp

echo "$1 $a" >>fileuseranswer.tmp

cat fileuseranswer.tmp >fileuseranswer

rm fileuseranswer.tmp

RC=0 ; break

fi

done

return $RC

}

while :

do

echo -e "Enter question number, N for next question, P for previous question or Q for done"

read a

case $a in

[1-8]*) [[ $a -gt $max ]] && c=$max || c=$a ; question "$c" ;;

n|N) [[ $c -lt $max ]] && let c+=1 || let c=1 ; question "$c" ;;

p|P) [[ $c -ge 1 ]] && let c-=1 || let c=$max ; question "$c" ;;

q|Q) exit 0 ;;

*) echo "Wrong choice , try again" ;;

esac

done

answers(){

echo -e "\c" > fileuseranswer

QNUM=0

TOTAL=0

while [ $QNUM -lt ${#questions[@]} ]

do

echo "\"${FILEUSERANSWER[$QNUM]}\" " >> fileuseranswer

[ "${CORRECT[$QNUM]}" = "${FILEUSERANSWER[$QNUM]}" ] && let SCORE=SCORE+1

let QNUM=QNUM+1

done

echo "You got $TOTAL questions correct out of ${#questions[@]}"

}

I want to be able to output and confirm my answers to the file fileansweruser where i already have my answers.Please help to troubleshoot these lines of code.

Thanks am ver grateful

i

Post the error you are getting.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.