Click here to Skip to main content
15,888,231 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm supposed to create a menu in shell programming comprises of a main menu something like this..

1) Add new book
2) Remove existing book info
3) Update book info and quantity
4) Search for book by title/author
5) Process a book sold
6) Inventory summary report
7) Quit


Each selection supposed to bring me to next page of it.
Anyone had the sample source code of it? I tried googling it around, can't find the desired tutorial for it too. Perhaps my lack of understanding on shell programming, I need to know too on be able to select a menu, which would direct it to that particular menu, perhaps stored at another .sh file?

Thanks a lot :)
Posted

Since you mention a .sh file, I guess you mean Unix or Linux shell scripting. There are several different types of shell language that you could be using though - sh/bash, tcsh/csh, ksh ...

For any of them the best place to look for information is the manual page - use "man bash" or "man csh" from the command line.
 
Share this answer
 
Use the below code: menu.sh

# ***** Code Starts here *****

until [ "$verify" = n ]
do
echo "1) Add new book"
echo "2) Remove existing book info"
echo "3) Update book info and quantity"
echo "4) Search for book by title/author"
echo "5) Process a book sold"
echo "6) Inventory summary report"
echo "7) Quit"
echo "select a menu"
read pattern
case $pattern in
1)
   echo "******Add new book*********"
   echo "Enter book name to create a new book"
   read bookname
   touch $bookname
   ;;
2)
  echo "******Remove existing book info*********"
  echo "Enter book name to remove the info"
  read bookname
  echo "" | cat>$bookname
   ;;
3)
  echo "******Update book info and quantity*********"
  echo "Enter book name to update the info"
  read bookname
  echo "enter text(title/author)" 
  read text
  echo $text | cat>>$bookname
   ;;
4)echo "******Search for book by title/author*********"
  echo "Enter title/author to search a book"
  read title
  echo "See the below list of files(books) having the entered title/author"
  find . -exec grep "$title" '{}' \; -print
  echo $text | cat>>$bookname
   ;;
6)
  echo "******Inventory summary report*********"
  echo "Enter book name to view the Inventory summary report"
  read bookname
  cat $bookname 
   ;;
7)
  exit case
  ;;
esac;
echo "Do u want to continue(Y/N)"
read verify
done

# ***** code ends here *****
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900