Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have installed Ubuntu on a VMWare virtual machine.

When I got to installing a VMWare tools, I have stumbled upon a simple question:

If I execute a script (perl script in VMWare tools case), is there a way for me to tell the execution beforehand, that if it prompts me for an input, given that it has a default value, it just uses it, not waiting for me to press Enter?

share|improve this question
    
Could you clarify what you mean, and what your end goal is? By 'default' do you mean enter the same string for every input, or separately for each? –  Chris Down Sep 20 '11 at 17:12

2 Answers 2

up vote 6 down vote accepted

yes is designed for this purpose; it outputs the same string to stdout continuously, so you can pipe it into another script and it will keep answering the same for every prompt. It defaults to y so it can say "yes" to the prompts, but if you just want it to send a newline each time you can pass it the empty string as an argument:

$ yes '' | vmware-script
share|improve this answer
    
Thank you. So even if I want to be sending newline of each prompt, I still use $ yes '' as shown in your example? –  Maxim V. Pavlov Sep 20 '11 at 17:47
    
@Maxim It outputs whatever string you give it, followed by a newline, so if you give it an empty string it will output just the newline. I used two single-quotes; yes "" will also work –  Michael Mrozek Sep 20 '11 at 17:50

Either patch the source to have a default, or use a here document or here string to send your input to the script's stdin:

./script << EOF
answer 1
answer 2
...
answer N
EOF

Certain programs may not accept this (usually ones handling authentication which may disable this for security purposes). In this case, look into using something like expect.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.