0

I execute python script by using bash script, it works fine. However I'm trying to find a way to get variable (for bash usage) from python execute. Example:

#!/bin/sh
 python Script.py Michael 17
 python Script.py Andrea 19
 echo "Script was executed with : Michael, 17 "
 echo "Script was executed with : Andrea 19"

Is there any way to get that variables ? I would like to avoid assigning eg. Michael, 17 to bash variables at the beginning.

Thanks.

1
  • 1
    Your question is unclear. Please review the guidelines on making a Minimal, Complete, Verifiable Example and consider editing your question to add enough material that someone wishing to help can be confident their answer produces the results you're looking for. Commented Oct 3, 2016 at 10:43

1 Answer 1

1

you can define arguments and pass these args to both as below;

#!/bin/sh
declare -a args1
declare -a args2

args1=("Michael" "17")
args2=("Andrea" "19")

python Script.py "${args1[@]}"
python Script.py "${args2[@]}"
echo "Script was executed with : ${args1[*]}"
echo "Script was executed with : ${args2[*]}"
Sign up to request clarification or add additional context in comments.

2 Comments

Hi, Honestly I thought about some other soultion. I would like to get access to variables separately. What if I would like to display only "Michael" instead of "Michael 17". My question was only an example.
${args1[0]} is "Michael".

Your Answer

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.