Operating System - Linux
1828208 Members
2252 Online
109975 Solutions
New Discussion

Re: called a script within a script that requires a response

 
SOLVED
Go to solution
f. halili
Trusted Contributor

called a script within a script that requires a response

Hello,

I'm calling a script in my scipt and the script I called is asking me "Are you sure y/n". In my script since I don't have to manually intervene, I want to automatically take "Y" for my answer. How can I put "Y" on my script?

thanks,
f. halili
derekh
6 REPLIES 6
OldSchool
Honored Contributor
Solution

Re: called a script within a script that requires a response

say your calling script "two", do this:

two <Y
EOF

man sh-posix and look at "hear" documents. Note, the "EOF" can be anything you want, but *must* be left-justified
Patrick Wallek
Honored Contributor

Re: called a script within a script that requires a response

Something like this in script1:

/path/to/script2 << EOF
Y
EOF


Please note that the EOF MUST start at the beginning of the line, UNLESS you do '<<-' then you can TAB over, NOT SPACE, to position EOF.
OldSchool
Honored Contributor

Re: called a script within a script that requires a response

note - I said "hear" docs...should be "here" docs...
James R. Ferguson
Acclaimed Contributor

Re: called a script within a script that requires a response

Hi:

# cat script1
#!/usr/bin/sh
echo "running..."
echo "YES!" | script2
echo "done"

# cat script2
#!/usr/bin/sh
read REPLY
echo "You said ${REPLY}"

# ./script1
running...
You said YES!
done

Regards!

...JRF...
A. Clay Stephenson
Acclaimed Contributor

Re: called a script within a script that requires a response

If you can anticipate all the responses, then all you need to do is create a file and redirect stdin or use a pipe.

echo "Y" | myscript.sh

Now when faced with more complicated choices (ie the questions change with varying conditions), that becomes the role of the expect utility.
http://hpux.its.tudelft.nl/hppd/hpux/Tcl/expect-5.43/

But for your simple case, reading from a file or pipe should suffice.
If it ain't broke, I can fix that.
f. halili
Trusted Contributor

Re: called a script within a script that requires a response

THANKS EVERYONE!
derekh