-1

I want to write a bash Script to launch a process with arguments.

As the following example: in the terminal i would launch the process and it will ask to chose a number. In terminal it would be :

user@u11:~$ process -someflag -someflag 
Hello ! Choose an option
1.blabla
2.do that
3.do the other

>>

Now, i want to launch the process with already the option selected in it but i couldn't succeed.

I can write this script :

#!/bin/bash
#script.sh

process -someflag -someflag 

If i run this script it will send me to the menu and make me choose a number. I want to provide this number inside the script. Is there any possibility ?

J.Doe
  • 3
  • 1
  • There is a possibility. Have you tried searching for something like "passing arguments to bash script"? – Mad Physicist Jul 11 '17 at 17:20
  • Perhaps https://stackoverflow.com/q/192249/2988730? – Mad Physicist Jul 11 '17 at 17:21
  • No, this do not answer my question because we cannot pass the arguments 1 or 2 or 3 to the process i am talking about before we have launched it and the menu has been displayed... – J.Doe Jul 11 '17 at 17:30
  • I think you can automate this with an `expect` script. – Jack Jul 11 '17 at 17:38
  • You question is unclear, do you ultimately want to launch your process with the options listed, e.g. if the user chooses `1.` you want `process --blabla`? – David C. Rankin Jul 11 '17 at 17:46

1 Answers1

0

First thing you should do, is to look for some extra flags for process to make it non-interactive/start it in batch mode.

If that is not supported. You may pipe the input to process.

choice=2
echo "$choice" | process -someflag -someflag

Or for multiple questions:

# Quesions 1
choice_1=3

# Quesions 2
choice_2=4

(echo "$choice_1"; echo "$choice_2") | process -someflag -someflag

But that is something you should try to avoid as the interface is designed for humans it is most likely not stable. (Order of questions/answers may change)

Mad Physicist
  • 107,652
  • 25
  • 181
  • 264
x539
  • 1,006
  • 6
  • 16