How to enter a return key in bash script?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to enter a return key in bash script?
# 1  
Old 05-25-2010
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 y, n, strings and a return. It looks to see if the software has already been installed and uses 2 different sets of responses.

The code for the here-now:

Quote:
if [[ -d /opt/lib/mflmf ]]; then
#
# perform install with no prompt to create /opt/lib/mflmf directory
#
print " - run install with existing /opt/lib/mflmf direc
tory"
sh ./install << EOF
y
y

y
n
y
n
y
64
n
n
EOF
else
#
# perform full install from scratch
print " - run install with no /opt/lib/mflmf directory"
sh ./install << EOF
y
y

y
n
y
/opt/lib/mflmf
y
n
y
64
n
n
EOF
fi
When I run this in Red Hat it fails. It seems to confuse the shell when it sees a blank line as it seems to dump the rest of the list and loops on a missing response.

Here is the failure point.

environment (and any compatibility environments).
Please press return when you are ready:
y
n
y
/opt/lib/mflmf
y
n
y
64
n
n
::::::::::::::
docs/env.txt
::::::::::::::


It responds correctly to the first 2 "y"s in the list. When it hits the blank line (return) is seems to accept a return but it grabs the remaining list of responses so the install program loops waiting for a response.

I've tried a blank line, multiple blank lines, a line with a blank character, /n and /r. Nothing seems to work.

Any help would be appreciated.

Mike Smilie
# 2  
Old 05-25-2010
Probably you might be better off using "expect".

Anyway, to enter a literal "ENTER key" open your scripts file in vi.

- Position the cursor where you want to enter the <ENTER> key and use "i" to go into insert mode.

- Then enter <CTRL>-<V>, which makes vi accept the next character as literal. Press the <ENTER> key then, which should result in a "^M" appearing on the screen.

- Press <ESC> to switch back to command mode and save. You're done.

Notice, that "^M" is not two characters (caret and "M"), but one. You will see that when you go over it with the cursor.

I hope this helps.

bakunin
# 3  
Old 05-26-2010
no luck

bakunin,

I tried your suggestion. No luck.

I stripped down the script to the single command for the here-now install:

Code:
 
sh ./install << HERE 
y 
y 
 
y 
n 
y 
n 
y 
64 
n 
n 
HERE

Still no luck.

Any other ideas?

Thanks

Mike
# 4  
Old 05-26-2010
What happens if you replace the blank line with "continue"

Code:
sh ./install << HERE 
y 
y 
continue
y 
n 
y 
n 
y 
64 
n 
n 
HERE

# 5  
Old 05-26-2010
No change with continue

---------- Post updated at 10:52 AM ---------- Previous update was at 10:38 AM ----------

I tried continue and return (yes, desperation beginning to show...)
# 6  
Old 05-26-2010
This construct does not work:

Quote:
sh ./install << EOF

EOF


Don't start another shell:

Code:
./install <<EOF

EOF

# 7  
Old 05-26-2010
not starting shell doesn't make a difference

This is the actual script where I removed the shell:


Code:
 
cd /opt/lib/cobol 
 
./install << EOF 
y 
y 
 
y 
n 
y 
/opt/lib/mflmf 
y 
n 
y 
64 
n 
n 
EOF

It runs and seems to process the first 2 responses correctly. When it reaches the point where it wants a return it seems to get confused.

This is the end of th elist generated:

Code:
 
Do you agree to the terms of the License Agreement? (y/n): 
--------------------------------------------------------------------------------
When you press return you will be shown details of the reference 
environment (and any compatibility environments). 
 
Please press return when you are ready: 
y 
n 
y 
/opt/lib/mflmf 
y 
n 
y 
64 
n 
n 
--More--(Next file: docs/env.txt)

It used the y for the question about license. The next line is the blank. It starts to display the env.txt file but it doesn't wait. It lists the remainig responses (for the next questions) and waits. If I cancel it loops on the next question after the return. It appears to be getting a response that it doesn't want.

Code:
 
Please confirm your understanding of the above reference environment 
details (y/n): Please enter y or n 
 
Please confirm your understanding of the above reference environment 
details (y/n): Please enter y or n 
 
Please confirm your understanding of the above reference environment 
details (y/n): Please enter y or n

Smilie
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

Input password to bash script, save, and enter when needed

I am looking for a way to start a script and have it prompt for a password that will be used later on in the script to SSH to another host and to SFTP. I don't want the password to be hard coded. Below is my script with the actual IP's and usernames removed. #!/usr/bin/expect -f... (2 Replies)
Discussion started by: jbrass
2 Replies

3. Shell Programming and Scripting

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... (4 Replies)
Discussion started by: kernel11
4 Replies

4. Shell Programming and Scripting

enter key or carriage return as input in perl

hi experts Question in perl i'm creating a script to take from user a different inputs one of them is the carriage return .. so that i want to make an if condition if the user hit enter key the user will go to previous step it something like that chomp ($input = <STDIN>); if ($input =~... (3 Replies)
Discussion started by: doubando
3 Replies

5. 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

6. 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

7. 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

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