Sponsored Content
Top Forums Shell Programming and Scripting Unix Shell Script: With Menu Option Post 302228315 by rc7 on Saturday 23rd of August 2008 10:51:52 PM
Old 08-23-2008
Code:
# Script to create menus and take action according to that selected menu item.
#
#
while :
  do
  clear
  echo "----------------------------------------------"
  echo " * * * * * * * Main Menu * * * * * * * * * * "
  echo "----------------------------------------------"
  echo "[1] Show Today's date/time"
  echo "[2] Show files in current directory"
  echo "[3] Show calendar"
  echo "[4] Start editor to write letters"
  echo "[5] Show IP's scanned by Nessus"
  echo "[6] Produce a Tabular Nessus Report"
  echo "[7] Produce a non-scan Tabular Nessus Report"
  echo "[8] Exit/stop"
  echo "----------------------------------------------"
  echo -n "Enter your menu choice [1-5]:"
  read yourch
  case $yourch in
    1) echo "Today is 'date' , press a key. . ." ; read -n 1;;
    2) echo "Files in 'pwd'" ; ls -l ; echo "Press a key. . ." ; read -n 1 ;;
    3) cal ; echo "Press a key. . ." ; read -n 1 ;;
    4) vi ;;
    5) echo "Enter your NBE file(s): \c"
       read FNAME
       for F in $FNAME; do
         awk -F"|" '/results/ {print $3}' "$F" | sort | uniq
       done
       ;;
    6) echo "Enter your NBE file(s): \c"
       read FNAME
       for F in $FNAME; do
         cat "$F" | awk -F"|" '$1 == "results" {gsub (/\n/,"",$7} printf {"%s\t%s\t%s\t%s\t%s\n", $3,$4,$5,$6,$7}' > ${F}_rawresults.txt
       done
       ;;
    7) echo "Enter your NBE file(s): \c";
       read FNAME; cat "$FNAME" | awk -F"|" '$1 != "results" {gsub (/\n/,"",$7); printf "%s\t%s\t%s\n", $1,$2,$3,&$7}' > non_results.txt
       ;;
    8) exit 0
       ;;
    *) echo "Opps!!! Please select choice 1,2,3,4,5,6,7 or 8"
       echo "Press a key. . ."
       read -n 1
       ;;
  esac
done

You have a typo on option 2: ech should be echo. You didn't terminate 7) and 6 correctly, also on option 7) printf "%s\t%s\t%s\n", $1,$2,$3,&$7} is missing a {. I've also added option "-n 1" to most read command so it'll accept any key, not just the return carriage. One more thought, most of the time you can use just awk to replace the combination (piping) of cat/grep/awk, as you can see in option 5.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

a main menu option?

I have created a main menu in the following way: while true; do echo " " echo "Main Menu: " echo "Please Select An Option Using The Options Provided." echo " " echo "1 - Search All Files" echo " " echo "2 - Search Individual Files" echo " " ... (1 Reply)
Discussion started by: amatuer_lee_3
1 Replies

2. Shell Programming and Scripting

script to show menu option & need to be autorun

hi i need to perform following task have to write script to display menu like 1) login as user1 2) login as user2 3) login as user3 4) go to shell script will be run through root user user1, user2 will be logged to specific thr account. if 4th option selected it must pass... (3 Replies)
Discussion started by: anup13
3 Replies

3. Shell Programming and Scripting

How do I add the option to change the path in a menu?

How do I add the option to change the path in a menu? I have this script. The user chooses a number and had the option of doing something, looking for log files etc. There is a possibility they might want to look at a different path other than what I have given them such as... (2 Replies)
Discussion started by: taekwondo
2 Replies

4. UNIX for Dummies Questions & Answers

What is a menu or command line option driven script?

i'm confused what this means. i was asked to design a menu or command line option driven script that reads out of a DB and displays info such as read_data.pl -u <user> -e <event> which would print commands run by <user>with the <event> in the db. any suggestions? i've been using... (2 Replies)
Discussion started by: kpddong
2 Replies

5. Ubuntu

Add Option To Right Menu

hey all, I already installed nautilus-actions now , I want to add "print path" script(option) to the right context menu!.. I did : http://img853.imageshack.us/img853/6973/59818245.png http://img847.imageshack.us/img847/8758/37217230.png the script print located in... (2 Replies)
Discussion started by: eawedat
2 Replies

6. Shell Programming and Scripting

sh file: READ (menu) but now run with option

I have a script which uses READ to detect choice of menu option...now I want to change the script without doing whole rewrite such that when user runs ./script.sh 5 it would execute menu option 5 rather than user running ./script.sh waiting for it to load and then pressing "5 enter" Is it... (1 Reply)
Discussion started by: holyearth
1 Replies

7. Shell Programming and Scripting

Script to call a menu script and redirect each option to a text file

Hello, I want to design a script that will call an existing menu script and select options one by one and redirict the out put to a file. For example;- In the script MENU.sh there are 10 options i want to design a script MENU2.sh that will select option 2 3 4 6 7 10 and redirict the output... (4 Replies)
Discussion started by: spradha
4 Replies

8. Shell Programming and Scripting

Menu shell script help

Hi All, I have written a shell script that show menu driven option. My requirement is that in the menu driven option i want to select multiple choice. i.e if i want to select 1 or 1,2 or 1,2,3 or 2,3 etc .... Can some one help me in that My script. while true; do echo " " ... (8 Replies)
Discussion started by: Nawrajesh
8 Replies

9. Shell Programming and Scripting

Menu Driven Bash Shell Script with Default Option

Hi All, I have written a menu driven bash shell script. Current Output is as below: ------------------------------------- Main Menu ------------------------------------- Option 1 Option 2 Option 3 Option 4 Exit ===================================== Enter your... (3 Replies)
Discussion started by: kiran_j
3 Replies

10. Shell Programming and Scripting

Need Menu option each on a new line

Here is my script for the menu options. # Bash Menu Script Example PS3='Please enter your choice: ' options=("Option 1:" "Option 2:" "Other Reason:" "Quit") select opt in "${options}" do case $opt in "Option 1 :") echo "you chose choice 1" ;; ... (3 Replies)
Discussion started by: mohtashims
3 Replies
SHTOOL-ECHO.TMP(1)					      GNU Portable Shell Tool						SHTOOL-ECHO.TMP(1)

NAME
shtool-echo - GNU shtool echo(1) extensional command SYNOPSIS
shtool echo [-n|--newline] [-e|--expand] string DESCRIPTION
shtool echo is an echo(1) style command which prints string to stdout and optionally provides special expansion constructs (terminal bold mode, environment details, date, etc) and newline control. The trick of this command is that it provides a portable -n option and hides the gory details needed to find out the environment details under option -e. OPTIONS
The following command line options are available. -n, --newline By default, output is written to stdout followed by a "newline" (ASCII character 0x0a). If option -n is used, this newline character is omitted. -e, --expand If option -e is used, string can contain special "%x" constructs which are expanded before the output is written. Currently the following constructs are recognized: %B switch terminal mode to bold display mode. %b switch terminal mode back to normal display mode. %u the current user name. %U the current user id (numerical). %g the current group name. %G the current group id (numerical). %h the current hostname (without any domain extension). %d the current domain name. %D the current day of the month. %M the current month (numerical). %m the current month name. %Y the current year. EXAMPLE
# shell script shtool echo -n -e "Enter your name [%B%u%b]: "; read name shtool echo -e "Your Email address might be %u@%h%d" shtool echo -e "The current date is %D-%m-%Y" HISTORY
The GNU shtool echo command was originally written by Ralf S. Engelschall <rse@engelschall.com> in 1998 for Website META Language (WML) under the name buildinfo. It was later taken over into GNU shtool. SEE ALSO
shtool(1), echo(1). 18-Jul-2008 shtool 2.0.8 SHTOOL-ECHO.TMP(1)
All times are GMT -4. The time now is 04:40 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy