Welcome to Home

Hi I’m Muhammad Hassaan studying Bachelor in Computer Science, I made my site for writing blogs related to new technologies which I m learning and some other interesting things.


Bash code

#!/bin/bash

## here we add our data in the file as a database
contact_list=contacts.txt

## confirmation the courses simple yes no options 
confirm(){
until [[ $confirmed =~ [YN] ]] ; do
read -p "Are you sure? Y/N: " confirmed

if [[ $confirmed = "Y" ]] 
then
   echo ""
   echo "---Contact Deleted---"
elif  [[ $confirmed = "N" ]]
	then
	return 1; main_menu
else
  echo "Must choose either Y/N - press crtl+c to exit"
fi

done
confirmed=											## when done keep checking the options 
}
keep_order(){
	sed -i 's/.*) //' $contact_list
	echo "$(awk '{print NR ")", $0}' $contact_list)" > $contact_list		## simply prints the document, without any parameters where printing is the entire record,
	sed -i '/^.\{,3\}$/d' $contact_list
}
search_course(){
    echo "[press q for main menu]"
	read -p "Enter name: " Instrc_name


	if [[ $ISBN =~ [qQ] ]] ; then 
	main_menu
	else
	grep -i "$ISBN" $contact_list || echo "NO matches"  
    fi
}

add_course(){
    echo "[press q for main menu]"
	sed -i '/^$/d' $contact_list
	line_number=($(wc -l $contact_list | awk '{ print $1 }'))
	line_num=$(( line_number + 1 ))
	

	##--------------ADD course-------

	read -p "Enter Course ID : " course_id
	if [[ $course_id =~ [qQ] ]] ; then 
	main_menu
	fi
	read -p "Enter course name: " fullname
	if [[ $fullname =~ [qQ] ]] ; then 
	main_menu
	fi
	read -p "Book ISBN number: " ISBN
	if [[ $ISBN =~ [qQ] ]] ; then 
	main_menu
	fi
    read -p "Enter Instructor name : " instrct
    if [[ $instructor =~ [qQ] ]] ; then 
	main_menu
	fi
	read -p "Enter email address: " email
	if [[ $email =~ [qQ] ]] ; then 
	main_menu
	fi
	# read -p "Enter cell number " phone
	# if [[ $phone =~ [qQ] ]] ; then 
	# main_menu
	# fi
		echo "$line_num) $course_id // $fullname //  $ISBN //  $instructor // $email // " >> $contact_list ## $phone 
		echo "--course Successfully Added---"
		echo ""

}