3 Replies - 331 Views - Last Post: 20 November 2019 - 09:44 PM Rate Topic: -----

#1 deannas99   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 21-January 19

Why is my code flashing?

Posted 20 November 2019 - 05:28 PM

Okay so I know the title of this is really dumb but I had no idea how else to put it. So for my one class we were given a .sh file with a bunch of errors and were told to fix it. So yeah I did that I thought I had the code fixed but there is something wrong with it that I cant figure out what, When I run the code in putty the output comes up but its like blinking and looks like its broken or something. I don't know any thoughts?

This is my code
#!/bin/bash
# File Name : cw4.sh
# Developer : Deanna Slotegraaf
# Date : November 20 2019
# Purpose : CW4 : Linux - Shell Scripting


while true
do
	clear
	echo -e	"\tDurham college employee list"
	echo "A. Add new employee"
	echo "B. Employee List"
	echo "C. Search for an employee"
	echo "D. Display number of employees for each Dept"
	echo "E. Exit from the Menu"
	echo ""
	read -r "Select your choice from the menu: " userChoice

	case $userChoice in
	  [Aa])
			echo ""
			echo "Enter the details for a new employee."
			echo ""
			read -r "Phone Number : " lastName
			read -r "Last Name    : " phoneNumber
			read -r "First Name   : " firstName
			read -r "Middle Name  : " middleName
			read -r "Dept No      : " deptNo
			read -r "Job Title    : " jobTitle
			read -r "Date Hired   : " dateHired
			record=$phoneNumber:$lastName:$firstName:$middleName:$deptNo:$jobTitle:$dateHired;
			cat -e "$record" < phone_list.txt
		    ;;

	    [Bb])
			clear
			cat phone_list.txt || awk '\BEGIN {FS="," ; printf "%-15s %-10s %-10s %-10s %-15s %-10s %-10s\n"
						"\--------------------------------------------------------------------------------------\n",
							"\Phone Number", "Last", "First", "Middle", "Dept No", "Job Title", "Date Hired"}
							\{printf "%-15s %-10s %-10s %-10s %-10s %-15s %-10s\n", $2, $1, $3, $4, $5, $6, $7}
							ENDD {print "--------------------------------------------------------------------------------------"}'

            		;;

	    [Cc])
			read -r "Please Enter A Phone Number : " phoneNo
			x=$(grep -i ^"$phoneNo" phone_list.txt)
		        if [ "$x" = "" ]; then
			   grep -i ^"$phoneNo" phone_list.txt >>listc.txt
			   # or can print formatted output as in (B)/> using awk command
			   awk '\BEGIN {FS=":" ;
			  \printf "%-15s %-10s %-10s %-10s %-10s %-15s %-10s\n------------------------------------------------------------------------------------------\n",
			  "\Phone Number", "Last", "First", "Middle", "Dept No", "Job Title", "Date Hired"}
			  \{printf "%-15s %-10s %-10s %-10s %-10s %-15s %-10s\n", $1, $2, $3, $4, $5, $6, $7}
			  END {print "--------------------------------------------------------------------------------------"}' listc.txt

		    else
			   echo "$phoneNo Not Found"
			fi
			;;

	    [Dd])
			cat < phone_list.txt | cut -d ':' -f6 | uniq -c > phone_list_count.txt
			cat < phone_list_count.txt | awk '\BEGIN {FS=":" ; printf "%-15s %-15s\n",
			        "Dept No.", "\No. of Employees-------------------------------"}
		                \{printf "%-15s %-15s\n", $1, $2}
                                END {print "--------------------------------\n"}'
			;;
        --*)
			echo "Invalid selection. Enter A, B, C, D, or E only."
			;;
	    [Ee])
		    echo "Hope you liked Linux shell scripting........"
			break
			;;
	esac
        read -r "Press any key to continue : "
END
done


Is This A Good Question/Topic? 0
  • +

Replies To: Why is my code flashing?

#2 Martyr2   User is offline

  • Programming Theoretician
  • member icon

Reputation: 5492
  • View blog
  • Posts: 14,465
  • Joined: 18-April 07

Re: Why is my code flashing?

Posted 20 November 2019 - 06:04 PM

Well a quick guess is that clear statement on line 10 which is clearing the screen each time around the loop. You print something, clear the screen, print something, clear the screen etc. This would cause a blinking effect. To see if that is the case, comment out the clear statement on line 10 and 37 to be safe and see if it blinks anymore.

Given that it is probably blinking non stop would tell you that you also have an infinite loop.
Was This Post Helpful? 0
  • +
  • -

#3 deannas99   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 21-January 19

Re: Why is my code flashing?

Posted 20 November 2019 - 06:56 PM

View PostMartyr2, on 20 November 2019 - 06:04 PM, said:

Well a quick guess is that clear statement on line 10 which is clearing the screen each time around the loop. You print something, clear the screen, print something, clear the screen etc. This would cause a blinking effect. To see if that is the case, comment out the clear statement on line 10 and 37 to be safe and see if it blinks anymore.

Given that it is probably blinking non stop would tell you that you also have an infinite loop.


Oh my god I'm an idiot

View PostMartyr2, on 20 November 2019 - 06:04 PM, said:

Well a quick guess is that clear statement on line 10 which is clearing the screen each time around the loop. You print something, clear the screen, print something, clear the screen etc. This would cause a blinking effect. To see if that is the case, comment out the clear statement on line 10 and 37 to be safe and see if it blinks anymore.

Given that it is probably blinking non stop would tell you that you also have an infinite loop.


I just made it so much worse now there is just lines and lines of bullshit
Was This Post Helpful? 0
  • +
  • -

#4 no2pencil   User is online

  • Professor Snuggly Pants
  • member icon

Reputation: 6824
  • View blog
  • Posts: 31,469
  • Joined: 10-May 07

Re: Why is my code flashing?

Posted 20 November 2019 - 09:44 PM

can you post your updated code?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1