LinuxQuestions.org
Help answer threads with 0 replies.
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 03-31-2004, 07:14 AM   #1
jorgecab
LQ Newbie
 
Registered: Mar 2004
Location: Madrid
Distribution: Red Hat
Posts: 1

Rep: Reputation: 0
send automatic input to a script called by another script in bash programming


Hi, I am working on a bash script in which I have to call another script that prompts for data from the user, the problem is that the data that it prompts I want to fill it automatically so the user only have to run my script and fill the data from the script I call from my own script. I used to do that with the expect library but I donṫ want to use it on this one and use only bash programming.

Does anybody knows how to send this data to the other script from the parent script? I hope I made myself clear...

Thanks for the help!!!

Jorge
 
Old 03-31-2004, 09:33 AM   #2
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Code:
#!/bin/bash
echo "This is the input" | the_other_script.sh
 
Old 04-01-2004, 12:20 AM   #3
rnturn
Senior Member
 
Registered: Jan 2003
Location: Illinois (SW Chicago 'burbs)
Distribution: openSUSE, Raspbian, Slackware. Previous: MacOS, Red Hat, Coherent, Consensys SVR4.2, Tru64, Solaris
Posts: 2,803

Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
Re: send automatic input to a script called by another script in bash programming

Quote:
I am working on a bash script in which I have to call another script that prompts for data from the user, the problem is that the data that it prompts I want to fill it automatically so the user only have to run my script and fill the data from the script I call from my own script.
Normally, when script A runs script B, it starts a new process to run that script. Script B inherits environment variables from script A. Any variables defined by script B are defined in its environment and they are lost when that script terminates. So script A doesn't know about the variables modified during B's run.

Except... if you don't spawn that new process. If you run script B in the same process, you can see B's variables. Try the following
Code:
#!/bin/bash
# Script A
echo "A: Running"
REPLY=undefined
. ./B
echo "A: Your reply was: ${REPLY}"
and
Code:
#!/bin/bash
# Script B
echo "B: What is your reply?"
read REPLY
(I sure hope that doesn't get garbled; there's pound signs and braces in those code blocks.) I think it'll do what you want. The thing that makes it work is the ". " (note the trailing space) before the script you're running. Of course, you'll have all those "reserved" environment variables that you have to watch out for if you invoke all your scripts this way. It'd be like dealing with BASIC variables or defining all your program variables in FORTRAN unnamed COMMON (uh oh, I'm dating myself :-) )

Anyway, hope this helped.

Good luck,
Rick
 
  


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
Shell script pipe input - bash mostly laikos Programming 4 11-09-2008 05:14 PM
cd keeps snapping back to current directory when called from bash script ghrellin Linux - General 5 08-28-2005 12:50 PM
bash script to send mail Cruger Programming 1 03-06-2004 08:25 AM
User input using a BASH script... causticmtl Programming 5 07-13-2003 09:59 PM
bash-script input aizkorri Programming 7 07-08-2003 06:15 AM

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

All times are GMT -5. The time now is 10:37 AM.

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