2

I have a shell script that calls a function from a python file that I created. That function needs two arguments, one string and one list of strings. I am trynig to figure out how can i call that script form the console. My scirpt is:

 #!/bin/sh
 cd $1
 python -c "from my_file import my_function; my_function( \"$2\" )"

The first argument is the path of my_file.py while the second one is a python list of strings. How can I call the script from the terminal?

My script is working if I call it from a python file like (and have input two strings for example):

arguments = ["./script.sh", path, args1]
ret_val = subprocess.Popen(arguments, stdout=subprocess.PIPE)

1 Answer 1

2

Perhaps you can pass it as command line argument to python.

#!/bin/sh
cd $1
python -c "from my_file import my_function; import sys; my_function(sys.argv[1])" $2
Sign up to request clarification or add additional context in comments.

2 Comments

My script is working when I call it from a python file like the posted example.
Ok, you can just call it with ./script path arg1_text?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.