I'm writing a CLI script that asks a series of questions before doing a few things. How can I pass them as arguments so that I don't have to keep entering them every time I want to test my script?
Basically, it should pass 4 items to STDIN, like "text1[ENTER]text2[ENTER]text3[ENTER]text4[ENTER]" automatically.
Yes, I could modify my script to actually read the shell arguments, but I don't want to do it that way, since it's supposed to run more like a wizard.
Looking for something like
SOMEPROGRAM myscript arg1 arg2 arg3 arg4
or
SOMEPROGRAM arg1 arg2 arg3 arg4 | myscript
Or something like that. Is there such a program?
Best Answer
I understand you do not want to modify
myscript
.Regarding the second solution you ask for, you can use
printf
:so that, defining an alias for SOMEPROGRAM as:
you could effectively call
The first form is ambiguous (from the point of view of SOMEPROGRAM), because it don't know where
myscript
options end and text parameters start, unlessmyscript
is effectively invoked without any options. In this case you could use a function:so that you could effectively call