run python script from bash script code example

Example 1: How to call one shell script from another shell script?

#!/bin/bash

#By Andrei Krasutski

SCRIPT_PATH="/path/to/script.sh"

# Here you execute your script
"$SCRIPT_PATH"

# or
. "$SCRIPT_PATH"

# or
source "$SCRIPT_PATH"

# or
bash "$SCRIPT_PATH"

# or
eval '"$SCRIPT_PATH"'

# or
OUTPUT=$("$SCRIPT_PATH")
echo $OUTPUT

# or
OUTPUT=`"$SCRIPT_PATH"`
echo $OUTPUT

# or
("$SCRIPT_PATH")

# or
(exec "$SCRIPT_PATH")

Example 2: How to run bash script in python

import subprocess
print "start"
subprocess.call("sleep.sh")
print "end"

Example 3: how to run a python script

# Save the script in a file with .py extension
# run the script using the below command
python fileName.py

Example 4: bash script python

subscription-manager register --username=admin --password=secret

Tags:

Java Example