Re: [SLUG] bash - moving up a notch

From: Kwan Lowe (kwan@digitalhermit.com)
Date: Wed Oct 05 2005 - 21:48:09 EDT


Mike Branda wrote:
> On Wed, 2005-10-05 at 18:19 -0400, Kwan Lowe wrote:
>
>>Mike Branda wrote:
>>
>>>anybody know how to in essence "auto fill" a read in sh/bash??
>>>
>>>for example:
>>>
>>>foo.sh runs another program inside itself that asks a question and then
>>>waits for a return off of a read. Based on a test of the question
>>>(redirected from stdout?) a predefined variable is entered as the answer
>>>and then returned somehow to the inside program.
>>>
>>>Is this possible? I have a config program that has to be run multiple
>>>times (different machines) with the same answers.
>>
>>I'm not certain but are you talking about some sort of default entry?
>>
>
>
> Yes
>
>
>>Can you give a more concrete example of what you're trying to accomplish?
>
>
> I'm not sure how but I'll try to explain it better. If you're asking
> for an example script...I'm not sure where to start this one... but if
> need be after this, I will try.
>
> Basically, I dont want to have to answer the same exact questions
> dozens of times. I want to do it once by hand, record the questions and
> my answers, look for what's unique in each question with the outer
> script and insert the proper answer stored in a variable form. All
> automated after the first one by hand. The alternative would be to hack
> the config file not to ask the questions (input reads) and just set it
> to the answers although there are a lot of if's to handle the returned
> possibilities.
>
> If the idea (auto filling the answers) is too clunky it's o.k. but I was
> wondering if it's even possible.

As Eben had mentioned, this sounds like something for 'expect'. You can
use it to "listen" for a particular string and then send a response.

Another option if you control the script that asks the questions is to
set default entries with the following syntax:

   ${foo:=bar}

This can be used like this:

---start
#!/bin/sh

echo "Enter something"
read foo

userinput=${foo:="yabbadabba"}
echo "foo is ${userinput}"

---end

If you run the script and enter a value, $userinput will contain the
value. If you just press enter, it will default to "yabbadabba".

-----------------------------------------------------------------------
This list is provided as an unmoderated internet service by Networked
Knowledge Systems (NKS). Views and opinions expressed in messages
posted are those of the author and do not necessarily reflect the
official policy or position of NKS or any of its employees.



This archive was generated by hypermail 2.1.3 : Fri Aug 01 2014 - 17:57:43 EDT