am new in python. am create a python script that return a string hello world. and am create a shell script. add a call from shell to python script.
- i need to pass arguments from shell to python.
- i need to print the value return from python in the shell script.
this is my code
shellscript1.sh
#!/bin/bash
# script for tesing
clear
echo "............script started............"
sleep 1
python python/pythonScript1.py
exit
pythonScript1.py
#!/usr/bin/python
import sys
print "Starting python script!"
try:
sys.exit('helloWorld1')
except:
sys.exit('helloWorld2')
Pass command line arguments to shell script to Python like this:
Print the return code like this:
You can't return message as exit code, only numbers. In bash it can accessible via
$?
. Also you can usesys.argv
to access code parameters:in shell: