简体   繁体   中英

Running a python script from shell

I want to run a python script from a shell script. I have been able to run it from the "command window" (Cygwin), but now I want to be able to call it from a shell script. It does not work the way I thought it would and the Internet has not really helped me with it.

My code so far:

#!/bin/bash
python Calibrate.py

I hope someone could help me further. Calibrate just contains a few basic command lines to transform some data that has been read in with an excelreader in the script itself.

Just make sure the python executable is in your PATH environment variable, then add in your script

In the file job.sh,

#!/bin/sh python <path/to/python/script>/python_script.py

Execute this command to make the script runnable for you : chmod u+x job.sh Run it : ./job.sh

A Bash script needs to use the Unix EOL (End Of Line) convention, which terminates each line with \\n . But it looks like your test.sh shell script file uses the Windows / DOS EOL convention, which terminates each line with \\r\\n .

You need to get rid of those \\r characters in test.sh, and you need to set your editor to use Unix line endings.

A simple way to strip \\r out of a file is to use the Unix sed command; I assume it's available in Cygwin:

sed -i 's/\r//g' test.sh

This removes all \\r characters in test.sh, writing the result back to test.sh

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM