1

I'm not sure what to search for this.

I am writing a piece of code using python fire to create a command line interface.

python test.py function argument

is there a way to make the shell interpret the following like the command above:

test function argument

Similar to how I can just call jupyter lab and it will open a notebook etc.

I have a feeling this is more to do with setting up my bashrc or similar instead of something I can do in Python.

2 Answers2

0

You're correct that it has to do with adding to your .bashrc. You want to set an alias.

  1. Make sure your code has an appropriate shebang line at the top, ex. #!/usr/bin/python3
  2. Add the following to .bashrc, ex. alias test=python3 /path/to/test.py

From there, you can use sys.argv in your code to handle arguments within the program.

will-hedges
  • 1,254
  • 1
  • 9
  • 18
0

Add the hashbang (at the start of the file, in case you don't know)
#!/usr/bin/env python
or
#!/usr/bin/env python3
Replace the 3 with whatever version you have installed and want that file to run
Save the file to an already existing PATH or add the file location to PATH
Now you can hopefully run it by typing test.py function argument
Rename test.py to test
Now you should be able to run it as test function argument
Also make sure your file is set as executable

natto
  • 63
  • 5