5

this is day one for me for bash. perhaps this question has already been asked, but i've tried google and have come up empty. maybe because i don't know how to articulate my question.

i have a custom/inhouse linux program that prompts the end user with a bunch of questions... and ultimately uses those questions to set up some servers. now i want to automate this so that a bash script will call the bin file and provide static answers. ideally i want to save the answers in a file, in the order that they are asked, and just feed it to the program.

Right now, I've been looking at sample scripts that read files. But I can't find an example that combines using file input and supplying answers to a program.

any pointers would be appreciated.

EDIT 1

I've tried to do the following:

#!/bin/bash echo "This script is about to call mytestapp" mytestapp printf 'lab\nci1\n6cr\n197\n0\n252\n888\n4\n\nAmerica/Toronto\n ~ 

When I run this, the "mytestapp" program launchs, but it sits there at the first question, waiting for input like this:

dev1:~# sh /tmp/test_wrapper.sh This script is about to call mytestapp Enter the 3-letter location code (e.g. usa): 

And the printf statement in the script never kicks in.

EDIT 2

i found my mistake. needed to pipe the params into the app:

 printf 'lab\nci1\n6cr\n197\n0\n252\n888\n4\n\nAmerica/Toronto\n' | mytestapp 
2

1 Answer 1

3

You can use your printf command, but it's usually easier to understand and maintain using a here-document:

mytestapp <<EOF lab i1 6cr 197 0 252 888 4 America/Toronto EOF 

    You must log in to answer this question.

    Start asking to get answers

    Find the answer to your question by asking.

    Ask question

    Explore related questions

    See similar questions with these tags.