2

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" 

    1 Answer 1

    2

    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.

    0

      You must log in to answer this question.

      Start asking to get answers

      Find the answer to your question by asking.

      Ask question

      Explore related questions

      See similar questions with these tags.