LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 08-14-2006, 09:04 AM   #1
basak
Member
 
Registered: Jul 2006
Posts: 41

Rep: Reputation: 15
giving the answer from the script


Hi againI hope that will be my final question about bash shell scriptsWell,is there a way to pass the y/n answer from a script to a command which outputs smth. like "Are you sure you want to remove specified job(s)? [y/n]:" to the screen when it is called from the terminal?
I use that command in my script but

File "/opt/edg/bin/edg-job-cancel", line 185, in ?
answ=UIutils.questionYN("Are you sure you want to remove specified job(s)?")
File "/opt/edg/bin/UIutils.py", line 171, in questionYN
ans=raw_input(question)
is what I get.I want to say "y" automatically to the command in the script when it asks..Is it possible?
 
Old 08-14-2006, 09:25 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2400Reputation: 2400Reputation: 2400Reputation: 2400Reputation: 2400Reputation: 2400Reputation: 2400Reputation: 2400Reputation: 2400Reputation: 2400Reputation: 2400
Hi,

Something like this maybe:

Code:
#!/bin/bash

echo -e "Remove XYZ (y/n)?: \c"
read answer
if [[ $answer == "y" ||  $answer == "Y" ]]
then
  echo "XYZ will be removed!"
else
  echo "Not removing XYZ."
fi
Hope this helps.
 
Old 08-14-2006, 09:27 AM   #3
penguintutor
Member
 
Registered: Jun 2006
Location: UK
Distribution: Ubuntu, Mandriva, Redhat and Fedora
Posts: 118

Rep: Reputation: 15
Does the command have an option to automatically pass a certain answer?

Most good command line programs should have a "non-interactive" mode.

If not then you should be able to redirect STDIN from a file.
The following example using rm -i (which requires a yes to confirm)

Create a file (yes.txt) with a single entry:
Code:
yes
then
Code:
rm -i delete.me < yes.txt
 
Old 08-14-2006, 09:36 AM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2400Reputation: 2400Reputation: 2400Reputation: 2400Reputation: 2400Reputation: 2400Reputation: 2400Reputation: 2400Reputation: 2400Reputation: 2400Reputation: 2400
Hi,

I think I misunderstood the original question.

Take a look at the yes command, the 'answer' given can even be manipulated (default is 'y').

General usage: yes | rm -i delete.me

Sorry about the possible confusion.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
What is the answer??? pxumsgdxpcvjm General 5 12-23-2005 10:00 PM
Burning a .dmg file Perl Script giving zlib error zwyrbla Linux - General 1 08-19-2005 04:02 PM
Does anybody know the answer........ BajaNick General 10 08-03-2003 10:46 AM
$10 - if you can answer Jaffy Linux - General 5 07-30-2003 12:53 PM
answer lakshman Linux - General 1 09-21-2002 01:18 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 01:13 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