script to ask the user to select a number


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers script to ask the user to select a number
# 1  
script to ask the user to select a number

hi all,

I have 4 scripts which i would need to run
1. BP.sh
2.DB.sh
3.LK.sh
4.TB.sh

I would like write a script which would ask the user to select a number from 1-4 accordingly and run only that script for him/her

I succeeded till reading the user input but not sure how to run that specific file ( lets say if user puts 2, then i need to run ./DB.sh)

echo " Please enter any one of the following values and press Enter"
echo "1 for BP"
echo "2 for DB"
echo "3 for LK"
echo "4 for TB"
echo "Enter value:"
read mInputValue
if ( $minputvalue = 1)
then......

Thanks in advance...
# 2  
Search for menu script.

Regards
# 3  
If your shell supports the select construct:

Code:
PS3='choose a script: '

select s in *sh; do
  ./"$s"
  break
done

# 4  
cannot execute the input script

1) *sh
choose a script: bp
all_scrt[4]: ./: 0403-006 Execute permission denied.


bp is having 777 permissions to execute
# 5  
Could you post the entire script? I'm wondering why the shell does not perform globbing on the *.
You should choose the number 1, 2 and so on:

Code:
% head *sh
==> BP.sh <==
echo $0

==> DB.sh <==
echo $0

==> LK.sh <==
echo $0

==> TB.sh <==
echo $0
% cat s
#! /bin/sh

PS3='choose a script: '

select s in *sh; do
  ./"$s"
  break
done

% ./s
1) BP.sh
2) DB.sh
3) LK.sh
4) TB.sh
choose a script: 1
./BP.sh


You could also change the code like this:

Code:
#! /bin/sh

PS3='choose a script: '

select s in *sh; do
  [ -e "$s" ] && ./"$s"
  break
done

# 6  
works

it worx ...thnk you
 

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #1002
Difficulty: Medium
During her lifetime, Grace Hopper was awarded over 100 honorary degrees from universities across the world for her work in computer science.
True or False?

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Select and copy .csv files based on row and column number

Dear UNIX experts, I'm a command line novice working on a Macintosh computer (Bash shell) and have neither found advice that is pertinent to my problem on the internet nor in this forum. I have hundreds of .csv files in a directory. Now I would like to copy the subset of files that contains... (8 Replies)
Discussion started by: rcsapo
8 Replies

2. Shell Programming and Scripting

List files with number to select based on number

Hi experts, I am using KSH and I am need to display file with number in front of file names and user can select it by entering the number. I am trying to use following command to display list with numbers. but I do not know how to capture number and identify what file it is to be used for... (5 Replies)
Discussion started by: mysocks
5 Replies

3. Linux

How to execute a simple select script using a shell script?

Hi team, I have two select statements and need to run them using SYSDBA user select * from temp_temp_seg_usage; select segment_name, tablespace_name, bytes/ (1024*1024) UsedMb from dba_segments where segment_name='TEMP_TEMP_SEG_USAGE'; Need to run this using a shell script say named... (1 Reply)
Discussion started by: pamsy78
1 Replies

4. Programming

MySQL select user with the same IP address

Dear community, I woul like to make a query to output all the users having the same IP address. The table is somethig like: name logged_ip ==== ========= user1 127.0.0.1 user2 127.0.0.2 user3 127.0.0.3 user4 127.0.0.1 user5 127.0.0.2 user6 127.0.0.5I used this query... (4 Replies)
Discussion started by: Lord Spectre
4 Replies

5. Shell Programming and Scripting

[Solved] Select the columns which have value greater than particular number

i have a file of the form 9488 14392 1 1.8586e-07 5702 7729 1 1.8586e-07 9048 14018 1 1.8586e-07 5992 12556 1 1.8586e-07 9488 14393 1 1.8586e-07 9048 14019 1 1.8586e-07 5992 12557 1 1.8586e-07 9488 14394 ... (1 Reply)
Discussion started by: vaibhavkorde
1 Replies

6. UNIX for Dummies Questions & Answers

How to read contents of a file from a given line number upto line number again specified by user

Hello Everyone. I am trying to display contains of a file from a specific line to a specific line(let say, from line number 3 to line number 5). For this I got the shell script as shown below: if ; then if ; then tail +$1 $3 | head -n $2 else ... (5 Replies)
Discussion started by: grc
5 Replies

7. Shell Programming and Scripting

Select matches between line number and end of file?

Hi Guys/Gals, I have a log file that is updated once every few seconds and I am looking for a way to speed up one of my scripts. Basically what I am trying to do is grep through a text file from start to finish once. Then each subsequent grep starts at the last line of the previous grep to... (4 Replies)
Discussion started by: Jerrad
4 Replies

8. Shell Programming and Scripting

awk to select a column from particular line number

The awk command awk -F: '{print $1}' test1 gives the first columns of all the lines in file ,is there some command to get a particular column from particular line . Any help is appreciated. thanks arif (4 Replies)
Discussion started by: mab_arif16
4 Replies

9. Shell Programming and Scripting

Script to count unique number of user loged in

Hi all, I am taking my first course in unix and having some problems. I would line to create a scrip that does the following: 1) will tell me the number of users logged in. If a user is logged more than once just count it only ones. 2) want to be able to display the number of users that... (1 Reply)
Discussion started by: elchalateco
1 Replies

Featured Tech Videos