-1

I have been searching for an answer to no avail. I have a python script that I would like to run that has quite a few arguments. It works just fine when I run the command from the terminal, but as soon as I try to put it in a bash script it no longer works.

script.py --arg1 --arg2 --arg3 --arg4 --arg5

This works.

#!/bin/bash
script.py --arg1 --arg2 --arg3 --arg4 --arg5

This does not. I get no error message or output.

jchan
  • 111
  • 2
  • 9
  • 6
    Please define what you mean by "doesn't work". Do you get any output? How are you running your script? – 0x5453 Feb 16 '18 at 20:24
  • 2
    What is the error message when you ran the bash script? – yaobin Feb 16 '18 at 20:26
  • Possible duplicate of [Call Python script from bash with argument](https://stackoverflow.com/questions/14155669/call-python-script-from-bash-with-argument) – sgc Feb 16 '18 at 20:27
  • Which shell is your terminal running? What is the error message? – cdarke Feb 16 '18 at 20:31
  • What I meant by doesn't work is I get no output or error message. If I append an echo 'Done' to the bash script, I never see the Done output. – jchan Feb 16 '18 at 21:32
  • How are you actually running the script? – chepner Feb 16 '18 at 21:39
  • I've done chmod +x on the script and am running it using ./bashscript.sh – jchan Feb 16 '18 at 21:40
  • There is nothing wrong with your Bash script as such. Something in your Python script is behaving differently when it is being invoked noninteractively. – tripleee Feb 19 '18 at 05:15

1 Answers1

0

Try this

#!/bin/bash
python script.py --arg1 --arg2 --arg3 --arg4 --arg5

The above assumes python executable is present in your path. If it is not you could also use the full path to python as follows

#!/bin/bash
/usr/bin/python script.py --arg1 --arg2 --arg3 --arg4 --arg5
Farooq Khan
  • 570
  • 4
  • 11
  • Why would this be necessary in the script, but not when he runs it by hand? – Barmar Feb 16 '18 at 20:33
  • I have tried adding the path to python as well as the full path to the script. I still see no output or error messages when executing the bash script. – jchan Feb 16 '18 at 21:39