0

I have an existing python code and i need to call a bash script from inside. The python code captures few variables and i need this to be passed to my shell to avoid duplicate input from user.

I have created a test script to simulate this, however, i am not able to echo the variables in shell ( it retuns a null )

1): Is it possible to pass the python variable to the shell script being called using subprocess? 2) If the below code can be optimized to achieve this, i am open to feedback.

Python code:

import os
import subprocess

first=input("Enter the first ip")
second=input("Enter the second IP")

subprocess.call(['bash','./script.sh',first,second])

Bash code (script.sh):

#!/bin/bash
###########################
echo "The First IP is $first"
echo "Enter your server "
read faulty_server
echo "The server is $faulty_server"
0

The 1st parameter in the Bash script is not called $first, but $1.

The 2nd parameter in the Bash script is not called $faulty_server, but $2.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.