Calling python script from bash

From raju

Sample scripts to demonstrate how to call a python script from bash.

Create a shell script that calls a pythyon script which prints the current working directory.

$pwd
/h/work/x

$cat pwd.sh
#! /usr/bin/env bash
set -e
set -u
dir=`"h:\work\x\getcwd.py"`
echo directory = $dir

$cat getcwd.py
#! /usr/bin/env python

import os
print(os.getcwd())

$chmod +x pwd.sh getcwd.py

Run the script

$./pwd.sh
directory = H:\work\x

Run the script in a different directory

$cd "C:\users\kkusuman"
$/h/work/x/pwd.sh
directory = C:\users\kkusuman