Deepak Verma
Deepak Verma

Reputation: 673

Linux:How to pass command line argument to an command line argument that is being passed to a script?

I have two scripts say script1.py and script2.sh.

script1.py takes as command line argument say "-t somethinng" and script2.sh takes script1.py as its command line argument say : script2.sh -class script1.py .

I can execute script1.py as standalone script by: "script1.py -t value" .

Now what I want to do is to pass command lines to script1.py at the same time when I am passing script1.py to script2.sh as command line argument.

I want to try something like this-

script2.sh --class script1:MyClass"-t value" --verbose

script2.sh is all set up to get Myclass from --class argument. Now above command is what i want to do . // where MyClass is a class in script1.py

Upvotes: 1

Views: 99

Answers (2)

hek2mgl
hek2mgl

Reputation: 157967

Brackets cannot being used here. The simplest and most common way would be to pass the whole python sub command-line as a string:

script2.sh -class "script1.py -t value" --verbose

Upvotes: 1

Erik Kaplun
Erik Kaplun

Reputation: 38217

Are script2.sh and script1.py your code or somebody else's?

If they are yours (or at least script2.sh), you can implement such feature yourself (using argparse or equivalent); if not, well there's no built in way to do that, as in: what you're asking has nothing to do with the generic Bash/shell functionality of passing arguments.

P.S. Or what @hek2mgl said might also just work.

Upvotes: 1

Related Questions