0

I have a file named "uscf" in /usr/local/bin:

#! /bin/sh
python3 ~/Desktop/path/to/uscf.py

I have already chmod +x this file so that I can run it from my terminal with the command "uscf". How can I run this with command line arguments so that the arguments are accessible through sys.argv in uscf.py?

EDIT: Added below example for clarification:

The uscf.py file:

import sys
if len(sys.argv) > 1:
print(sys.argv)

Running it from the command line:

Abraham$ uscf these are arguments

Expected output:

these are arguments
5
  • did you mean to say that you want to take input from the python script, here uscf.py ? Commented Aug 17, 2018 at 4:09
  • Are you talking about argparse? docs.python.org/3/library/argparse.html Commented Aug 17, 2018 at 4:10
  • No, I want to run the unix executable through the command line and give it some arguments Commented Aug 17, 2018 at 4:10
  • 1
    I would make it #!/usr/bin/python and have setup.py have scripts section to call your python executable with argparse or argv Commented Aug 17, 2018 at 4:12
  • See jordanm's answer, it is what I was looking for. I also added an edit for clarification Commented Aug 17, 2018 at 4:19

1 Answer 1

2

In sh the "$@" variable contains all the positional arguments passed to the script. You can use that to pass it to your python script:

#!/bin/sh
python3 $HOME/Desktop/path/to/uscf.py "$@"
Sign up to request clarification or add additional context in comments.

1 Comment

You cannot use ~ for $HOME in sh scripts. See also Difference between sh and bash

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.