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"
-
This should help stackoverflow.com/q/5826427/2975396TheGameiswar– TheGameiswar2021年03月12日 12:41:01 +00:00Commented Mar 12, 2021 at 12:41
-
1Does this answer your question? Can a python script execute a function inside a bash script?TheGameiswar– TheGameiswar2021年03月12日 12:41:27 +00:00Commented Mar 12, 2021 at 12:41
-
Actually, no because it is directly calling the function I have to pass the argument from python to bash. Thanks BTW.Mehul Anshumali– Mehul Anshumali2021年03月12日 12:44:57 +00:00Commented Mar 12, 2021 at 12:44
1 Answer 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
Muhammad Huzaifa
731 silver badge9 bronze badges
Sign up to request clarification or add additional context in comments.
3 Comments
Mehul Anshumali
Thank you so much working ... I had spent 1 week to figure out this thing. Thank You so much 😊
Mehul Anshumali
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
Muhammad Huzaifa
I have updated the answer with the solution
default