PECS questionnaire turned into a bash script
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

109 lines
3.0 KiB

  1. #!/bin/bash
  2. #
  3. # Copyright 2020, Job Bautista
  4. # Licensed under the Eiffel Forum License 2.
  5. # See the COPYING file for the full license text.
  6. question=1
  7. programdone () {
  8. echo "Program done. Exiting."
  9. exit
  10. }
  11. echo "Welcome to the" `cat config/testname`.
  12. echo "Read each statement carefully and answer honestly based on how well"
  13. echo "it describes you. There are five choices. Enter the number you selected."
  14. echo "---------------------------------------------------------------------------"
  15. echo "5="`cat config/5`
  16. echo "4="`cat config/4`
  17. echo "3="`cat config/3`
  18. echo "2="`cat config/2`
  19. echo "1="`cat config/1`
  20. read -p "Ready? (y/yes to proceed, anything else to exit): " ready
  21. case $ready in
  22. "yes" | "YES" | "Yes" | "y" | "Y")
  23. while [ $question -le 55 ]
  24. do
  25. echo "$question." `cat questions/$question`
  26. read -p "Answer: " num$question
  27. ((question++))
  28. done
  29. ;;
  30. *)
  31. programdone
  32. ;;
  33. esac
  34. score1pre=$((num1 + num12 + num23 - num34 + num45))
  35. score2pre=$((num2 + num13 + num24 - num35 + num46))
  36. score3pre=$((num3 + num14 + num25 + num36 - num47))
  37. score4pre=$((num4 + num15 + num26 + num37 - num48))
  38. score5pre=$((num5 - num16 + num27 + num38 + num49))
  39. score6pre=$((num6 - num17 + num28 + num39 + num50))
  40. score7pre=$((num7 + num18 - num29 + num40 + num51))
  41. score8pre=$((num8 + num19 + num30 - num41 + num52))
  42. score9pre=$((num9 - num20 + num31 + num42 + num53))
  43. score10pre=$((num10 - num21 + num32 + num43 + num54))
  44. correctionpre=$((num11 - num22 - num33 - num44 + num55))
  45. correction=$((correctionpre+18))
  46. score1=$((score1pre+6))
  47. score2=$((score2pre+6))
  48. score3=$((score3pre+6))
  49. score4=$((score4pre+6))
  50. score5=$((score5pre+6))
  51. score6=$((score6pre+6))
  52. score7=$((score7pre+6))
  53. score8=$((score8pre+6))
  54. score9=$((score9pre+6))
  55. score10=$((score10pre+6))
  56. echo "---------------------------------------------------------------------------"
  57. echo "Results (without correction):"
  58. echo `cat config/score1name` "= $score1"
  59. echo `cat config/score2name` "= $score2"
  60. echo `cat config/score3name` "= $score3"
  61. echo `cat config/score4name` "= $score4"
  62. echo `cat config/score5name` "= $score5"
  63. echo `cat config/score6name` "= $score6"
  64. echo `cat config/score7name` "= $score7"
  65. echo `cat config/score8name` "= $score8"
  66. echo `cat config/score9name` "= $score9"
  67. echo `cat config/score10name` "= $score10"
  68. echo "Correction Factor = $correction"
  69. if [ $correction -le 19 ]
  70. then
  71. programdone
  72. else
  73. case $correction in
  74. 24 | 25)
  75. subtract=7
  76. ;;
  77. 22 | 23)
  78. subtract=5
  79. ;;
  80. 20 | 21)
  81. subtract=3
  82. ;;
  83. *)
  84. echo "This shouldn't happen. Either you inputted a number greater than 5, or this is a bug."
  85. programdone
  86. ;;
  87. esac
  88. echo "---------------------------------------------------------------------------"
  89. echo "Results (with correction):"
  90. echo $((score1 - subtract))
  91. echo $((score2 - subtract))
  92. echo $((score3 - subtract))
  93. echo $((score4 - subtract))
  94. echo $((score5 - subtract))
  95. echo $((score6 - subtract))
  96. echo $((score7 - subtract))
  97. echo $((score8 - subtract))
  98. echo $((score9 - subtract))
  99. echo $((score10 - subtract))
  100. fi