0

Suppose I have two functions function_arguments1 and function_agruments2 which are accepting parameters. I want to call the function name:- function_argument1, from python script. How should I call the function_arguments1 from Python passing parameters from python script.

#!/bin/bash 
#Script to pass and access arguments 
 
function_arguments1(){ 
 echo 1ドル 
 echo 2ドル 
 echo 3ドル 
 echo 4ドル 
 echo 5ドル 
} 
 
function_argument2(){
 echo 1ドル 
 echo 2ドル 
}
#Calling function_arguments2 
function_arguments2 "Please""Help" 
asked Mar 12, 2021 at 12:34
3

1 Answer 1

1
import subprocess
subprocess.Popen(['bash', '-c', '. bash_script.sh; function_argument2 Please Help'])

To pass input arguments from a list:

inputs = ['Hello', 'How', 'What']
for input_ in inputs:
 subprocess.Popen(['bash', '-c', f'. bash_script.sh; function_argument2 {input_}'])
answered Mar 12, 2021 at 12:48
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you so much working ... I had spent 1 week to figure out this thing. Thank You so much 😊
Hey, i have one doubt lets say i have to repeat this process again and again. so i will the for loop like for i in function_call_list: (function call list is a list of parameters say ['Hello', 'How', 'What']. So when i write the subprocess.Popen(['bash', '-c', '. bash_script.sh; function_argument2 i ']) i value it is not taking. what should i do
I have updated the answer with the solution

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.