dasfex
dasfex

Reputation: 1260

How to execute program with parameters which I got?

I have some script a.py and can execute it with some parameters

./a.py 1 2 --h 'Hi!'

Also I have bash script sh.sh. And I want to do something like this:

./sh.sh ./a.py 1 2 --h 'Hi!'

And then a.py start with these parameters. What I should write in sh.sh?

Upvotes: 0

Views: 38

Answers (2)

aashoo
aashoo

Reputation: 404

Below the list of special variables provided by the shell that you can use in your shell script directly.

Variable     Variable Details
$#          :  Total number of arguments passed to script
$0          :  Script name itself
$1 to $n    :  $1 for the first arguments, $2 for second argument till $n for n’th arguments. From 10’th argument, we must enclose them in curly braces eg. ${10}, ${11}
$*          :  Values of all the arguments. All agruments are double quoted
$@          :  Values of all the arguments
$?          :  Exit status id of last command
$$          :  Process ID of current shell
$!          :  Process id of last command

Upvotes: 0

Tom Fenech
Tom Fenech

Reputation: 74596

If you run the command:

./sh.sh ./a.py 1 2 --h 'Hi!'

Then inside the shell script, the contents of the array $@ will be:

'./a.py' '1' '2' '--h' 'Hi!'

So if you want to run that, you can just use:

"$@"

Upvotes: 1

Related Questions