0

I am trying to make a bash command that runs my python code, so I don't have to input python reboot.py <arg> every time I want to run my code. (unrelated - I am using the reboot to reboot my discord.py bot). Does anyone know how I can take an argument in when I run it and run the python code using the argument?

#!/bin/bash
# hdhuihfuiewfh
ARG1 = $1
cd directory/of/my/project/is/here
python reboot.py ARG1


This is my bash code. Everything runs fine, but the argument won't get passed into the python code and I get the error ./dynamite.sh: line 3: ARG1: command not found

Here is my python code:

import sys

if sys.argv is True:
    if sys.argv[1] == 'reboot':
        print("Rebooting dynamite...")
    elif sys.argv[1] == 'kill':
        print("Killing dynamite...")
        #do logout stuff

else:
    print("Please input an argument")

If you still don't understand, the python code takes in an argument, and when I run the code in the bash script I want to be able to input an argument. For example, I want to be able to run ./dynamite.sh kill, and that will do the kill part of the python code. If I run the python code without the bash script and input an argument then it works, I just don't know how to pass in an argument with the bash code. Could anyone please show me how to input an argument then run the python code with the argument? I'm on macOS.

Oblique
  • 560
  • 1
  • 4
  • 18
  • Shouldn't that be `python reboot.py $ARG1`? Using the dollar sign you get the value. – JQadrad May 17 '20 at 02:29
  • I changed it but still get this error ./dynamite.sh: line 3: ARG1: command not found – Oblique May 17 '20 at 02:31
  • 1
    You can't have spaces around `=` in the assignment, see the duplicate. You could even skip the assignment entirely and use `python reboot.py "$1"` instead. – Benjamin W. May 17 '20 at 02:32

0 Answers0