How to pass enter key or selected character in bash script?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to pass enter key or selected character in bash script?
# 1  
Old 10-29-2013
How to pass enter key or selected character in bash script?

hi,
i've bash script thats working...
but now i need to add a line....that prompts for user input....like yes and 1 as complete install....

so here's how it looks...

$ cd 9200 (cd into directory)

$./install (hv to type ./install to run install then ask for)
----do you want to install
press y for yes n for no.
Y (here's needs to press Y------this is where i stuck)

then it prompts for

1 for complete install or 2 for server install
1 (here needs to press 1 ---------this is where i stuck)


then it completes the installation.

needed script to select Y for yes and then 1 for complete automatically and finish the installation....
would be great to hear.

thanks
# 2  
Old 10-29-2013
Checkout the read command then proceed based on the entered answer:

Code:
read -p "Do you want to install? [y,n]:  " answer

# 3  
Old 10-29-2013
Try

Code:
$ cat s.sh 
#!/bin/bash

echo -n "Do you want to install press [yes] to install  [no] to stop: "
read yno
case $yno in

        [yY] | [yY][Ee][Ss] )
                echo "Received Permission"
                ;;

        [nN] | [n|N][O|o] )
                echo "No, installation terminates here";
                exit 1
                ;;
        *) echo "Invalid input"
            ;;
esac

Code:
$ bash s.sh
Do you want to install press [yes] to install  [no] to stop: yes
Received Permission

$ bash s.sh
Do you want to install press [yes] to install  [no] to stop: n
No, installation terminates here

$ bash s.sh
Do you want to install press [yes] to install  [no] to stop: 
Invalid input

# 4  
Old 10-29-2013
Thank you all for your prompt help & suggestion.

i think i didn't clarify earlier my mistake...sorry abt that.

actually,
$./install (is the program the vendor provided inorder to install software)
during installation it will prompt for Yes for Y after that 1 for complete install...
so basically,

#!/bin/bash
mount -t nfs 192.168.1.100:/software /temp (where its located on the network)
./install

after that i want script to enter Yes for Y and 1 for complete install...

is that something doable...would be glad to hear.

thanks much.
# 5  
Old 10-29-2013
Did you consider stdin redirection?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script termination without pressing Enter key[nohup]

I have a script in which we have used nohup. Once script is executed it will be terminated only when enter key is pressed. I want the script to be terminated without pressing enter key nohup imqbrokerd -name user_id port 2>1 1>$home_`date` & I am a newbie to shell, Kindly please help (3 Replies)
Discussion started by: Suganbabu
3 Replies

2. Shell Programming and Scripting

How to pass Enter key stroke , tried all options?

Hi Friends, I am unable to pass Enter key stroke to shell script. Tried all options, but no luck. Please help.. Script: bkpscript.sh tam01# ./bkpscript.sh < file.txt Mount volume 1 on /dev/rmt0. Press Enter to continue. tam01# tam01# tam01# tam01# echo ""... (5 Replies)
Discussion started by: suresh3566
5 Replies

3. Shell Programming and Scripting

How to enter a return key in bash script?

Hi, I'm porting an install script from AIX to Red Hat (2.6.18-164.el5 #1 SMP) I have this script working in both AIX and HP-UX. The script is a wrapper for a Micro Focus Server Express install program. It responds to the install program questions with a here-now list. Responses includes... (14 Replies)
Discussion started by: duker61
14 Replies

4. Shell Programming and Scripting

Simulating enter key via shell script

How to simulate enter key via shell script (2 Replies)
Discussion started by: proactiveaditya
2 Replies

5. Shell Programming and Scripting

BASH: Any Way to Get User Input Without Requiring Them to Hit the Enter Key?

I'm working on making a menu system on an HP-UX box with Bash on it. The old menu system presents the users with a standard text menu with numbers to make selections. I'm re-working the system and I would like to provide something more akin to iterative search in Emacs. I have a list of 28... (2 Replies)
Discussion started by: deckard
2 Replies

6. Shell Programming and Scripting

How to catch ENTER key inside the shell script?

Hi, I have a script in which i have to ask user to press the ENTER key to proceed further. can you please help me how can i achive this in my scripting? echo "All the executables builded Successfully " echo " Press Enter to Go Back to the Main Menu" ... (2 Replies)
Discussion started by: plaban.rout
2 Replies

7. Shell Programming and Scripting

Enter Crtl+U character in shell script

hi I have some program which accepts "Crtl+U" input, Now i want to run it thorugh my written script ...all other inputs are accepted but how to supply this input. I am supplying input parameters to the program named EX as below. ================================= main.sh . . EX<<EOF... (3 Replies)
Discussion started by: ashish_uiit
3 Replies

8. Shell Programming and Scripting

writing Enter key inside in shell script

for automating telnet using shell script..... as we enter alphabetic characters inside shell script...how can we do the same for the enter key......Is there any character for the enter key so the enter key need not be pressed manually...... (3 Replies)
Discussion started by: bishweshwar
3 Replies

9. UNIX for Advanced & Expert Users

using enter key in shell script

without pressing the enter key ..manually... how can we read the enter key ..from the shell script..so that the script termintes automatically. eg: telnet a.b.c.d xxxx now " how to read the enter key" tho terminate the script (1 Reply)
Discussion started by: bishweshwar
1 Replies

10. UNIX for Dummies Questions & Answers

Pressing backspace key simulates enter key

Hi, Whenever i press the backspace key, a new line appears, i.e. it works like a enter key. :confused: Thanks (2 Replies)
Discussion started by: vibhor_agarwali
2 Replies
Login or Register to Ask a Question