How to call Python script from bash with an agrument?

0 votes
I want to pass an argument in my python script from my bash script, how can I do that?
Jun 24 in Python by Taj
• 1,040 points

1 answer to this question.

0 votes


You need to call the same command that you would use within terminal to execute a python script in bash script.

For instance:

python arg1 arg2

And to access these arguments in python you can use:

import sys
print sys.argv[0] # prints
print sys.argv[1] # prints agr1
print sys.argv[2] # prints agr2
answered Jun 24 by Shabnam
• 920 points

Related Questions In Python

0 votes
1 answer

how to exit a python script in an if statement

This works fine for me: while True: ...READ MORE

answered Sep 19, 2018 in Python by bug_seeker
• 15,360 points
0 votes
1 answer

I'm using Python 2.7 to convert an XML response (from a REST call to Atlassian Fisheye) into an HTML table.

You don't have a template matching tabularQueryResult in your ...READ MORE

answered Oct 4, 2018 in Python by Priyaj
• 56,940 points
0 votes
1 answer

Is it possible to call one python script from another Python Script?

Yes it is possible. Suppose your script ...READ MORE

answered Jul 2 in Python by Arvind
• 2,960 points
0 votes
1 answer
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 349 views
0 votes
1 answer

How to add a new Python interpreter in PyCharm?

Refer to the below screenshots: Then set a ...READ MORE

answered May 30 in Python by Shabnam
• 920 points
+1 vote
1 answer

How to check if a string is in a file, using python?

Hi, Try the below given code: with open('myfile.txt') as ...READ MORE

answered Jul 4 in Python by Shabnam
• 920 points