LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-23-2012, 01:55 PM   #1
ReverendDangles
LQ Newbie
 
Registered: Apr 2012
Location: Huntsville, AL
Distribution: Fedora 16
Posts: 14

Rep: Reputation: Disabled
Shell scripting: Pressing 'Enter'


I have a shell script I'm making to automate some CIAO processes. It's working fine but I can't leave it alone to go work on other stuff b/c it queries me for parameter responses ('Enter','yes','no','filename',etc).
All of these parameters I have already defined in the script but the program the script is running produces these queries anyway. So bottom line is I just need to press 'Enter' whenever a query pops up.

Example:

Code:
user$ ./specextract.sh
...
...
Combine ungrouped output spectra and responses? (no): 
Create background ARF and RMF? (yes):  

                                                      
Running: specextract                                  
  Version:    14 February 2012
Is there a way to incorporate the responses into the script?

Any help is greatly appreciated.
Thank you!
 
Old 05-23-2012, 01:59 PM   #2
millgates
Member
 
Registered: Feb 2009
Location: 192.168.x.x
Distribution: Slackware
Posts: 852

Rep: Reputation: 389Reputation: 389Reputation: 389Reputation: 389
Hi, have you tried something like

Code:
yes "" | ./script
 
Old 05-23-2012, 03:21 PM   #3
ReverendDangles
LQ Newbie
 
Registered: Apr 2012
Location: Huntsville, AL
Distribution: Fedora 16
Posts: 14

Original Poster
Rep: Reputation: Disabled
Yes I have and it didn't work.

I've looked around at other forums and they say something about using expect
but it looks like it wouldn't work for me.
 
Old 05-23-2012, 04:23 PM   #4
millgates
Member
 
Registered: Feb 2009
Location: 192.168.x.x
Distribution: Slackware
Posts: 852

Rep: Reputation: 389Reputation: 389Reputation: 389Reputation: 389
Quote:
Originally Posted by ReverendDangles View Post
Yes I have and it didn't work.
What does "didn't work" mean exactly?

Quote:
Originally Posted by ReverendDangles View Post
I've looked around at other forums and they say something about using expect
but it looks like it wouldn't work for me.
Why wouldn't it work for you? How long is the script? Can you post it (or relevant portions of it)?
 
Old 05-23-2012, 05:13 PM   #5
ReverendDangles
LQ Newbie
 
Registered: Apr 2012
Location: Huntsville, AL
Distribution: Fedora 16
Posts: 14

Original Poster
Rep: Reputation: Disabled
Excuse me.
The script itself still runs but the prompts still pop up.

Code:
#!/bin/bash
#
# specextract script
#
# the .reg files are generated from using ds9 and 
# should be labeled src.reg and bkg.reg 
#

-----bunch of parameter definitions-----

. /usr/local/ciao/bin/ciao.bash

punlearn specextract  
 specextract infile="$EVT[sky=region($SRC)]" \
             outroot=simple  \
             bkgfile="$EVT[sky=region($BKG)]" \
             asp=$ASOL  \
             pbkfile=$PBK \
             mskfile=$MSK  \
             badpixfile=$BAD \
             weight=yes correct=no \
             grouptype=NUM_CTS binspec=15
output is:

Quote:
user$ yes "" | /<path>/specextract.sh
CIAO configuration is complete...
CIAO 4.4 Friday, December 2, 2011
bindir : /usr/local/ciao/bin
Combine ungrouped output spectra and responses? (no):
Create background ARF and RMF? (yes):

Running: specextract
Version: 14 February 2012
So I still need to give the program my response with the yes command.

punlearn is to restore the system default parameter values

Last edited by ReverendDangles; 05-23-2012 at 05:18 PM.
 
Old 05-23-2012, 05:30 PM   #6
millgates
Member
 
Registered: Feb 2009
Location: 192.168.x.x
Distribution: Slackware
Posts: 852

Rep: Reputation: 389Reputation: 389Reputation: 389Reputation: 389
Do you have an idea where do those prompts come from? From the ciao.bash script? From the specextract binary? Or somewhere in the "bunch of parameter definitions" part?
for example, if the parameters are read with something like

Code:
read -p "Do you want whatever?" -e -i "yes" variable
You may try giving the script the default answers, such as

Code:
echo -e "yes\nyes\nyes\nno\nwhatever" | ./specextract.sh
or
Code:
./specextract << _EOF_
yes
yes
yes
no
whatever
_EOF_
 
Old 05-23-2012, 05:53 PM   #7
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
if you have access to the script source can you replace the read commands with the value of the variable you want.
 
Old 05-23-2012, 05:59 PM   #8
ReverendDangles
LQ Newbie
 
Registered: Apr 2012
Location: Huntsville, AL
Distribution: Fedora 16
Posts: 14

Original Poster
Rep: Reputation: Disabled
I could only find the binaries on my work computer so I cannot be
certain but I believe these are coming from the specextract binary.
I found the names of these two boolean switchesset them to 'no' and
'yes' respectively and that solved the problem.

I'm not sure if what I wanted to do was valid for this instance but
you actually helped me with another script I have so your knowledge
did not go unappreciated. Thank you very much!
 
Old 05-24-2012, 05:11 PM   #9
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
Well, it seems you've solved it, but in future cases you might also look into writing an expect script. That's its whole purpose -- automating user input.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to simulate a ENTER key pressing khaos83 Linux - Newbie 2 08-06-2008 04:41 AM
Leave vi mode without pressing enter ? Vilius Linux - General 4 11-13-2007 04:12 AM
Unix Shell Scripting, detecting the enter key WinterSt Programming 7 09-01-2004 08:27 AM
Mandrake 10 doesnt install after pressing enter subliminal Mandriva 9 06-17-2004 03:04 PM
I did the following program and get blank line after pressing <ENTER> purpleburple Programming 5 08-21-2002 12:00 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:31 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration