isk27
isk27

Reputation: 359

How to pass an argument to shell script

I'm kinda new in bash, the thing is I need to run several set of data in a program, I make a bash script that allow me to do it automatically... the problem is when the program start it needs some inputs and I don't know how to give it inside the bash? I execute the program:

$./bin/mg5_aMC

The program opens and I need to pass some input to run (mg5> is the enviroment of the program):

mg5>launch file.lhe

the program runs, and ask for something:

mg5> 1

and then again, ask for something and i need to press enter..

mg5> (enter)

PD.: I edited the question because I suppose didn't express myself very well..

Upvotes: 1

Views: 1362

Answers (3)

InfectedPacket
InfectedPacket

Reputation: 274

From what I understood from your question, you either want 1) to pass parameters when calling your Bash script, or 2) some sort of interactive shell within your script.

For #1, passing parameters to a Bash script, these links may be helpful:

Basically, you need to use the following call for your script:

./bin/mg5_aMC launch xxx.lhe 1

And within your script, you refer to each argument using a numbered variable:

action=$1
file=$2
n=$3

As for #2, consult the following links/examples:

There are quite a few resources online and on this site that will provide you more example and explanations.

Upvotes: 1

grimsock
grimsock

Reputation: 794

From what I see, you rather want to catch user's input, than simply pass args to executed script. read command allows you to catch user's input. Did it answers your question?

Upvotes: 0

vsoftco
vsoftco

Reputation: 56577

If the program can get its input as arguments passed from the command line, then you can write the parameters in a file, call it e.g. params, then do

./bin/mg5_aMC $(<params)

Upvotes: 0

Related Questions