0

I wrote a bash that has python command included in loop: (part of script)

#!/bin/bash

ARG=( $(echo "${@:3}"))
for (( i=1; i<=$#-3; i++ ))
do
python -c "print('<Command with variables>' * 1)"
done

When I run it, depends on number of my args for example I have this output:

nohup command-a &
nohup command-b &
nohup command-c &

How do I execute the output lines from bash immediately?

Can I tell python command to run them in each iteration? How?

Thank you

2 Answers 2

1

You can achieve that by executing the python code in a sub-shell and evaluating the content of that shell afterwards.

eval $(python -c ...)

$() returns a string you can evaluate with eval

Sign up to request clarification or add additional context in comments.

Comments

0

You are asking two questions. I can only answer the first one:

If you want to run commands coming to the standard output, just redirect them to bash:

python -c 'print "ls"' | bash

1 Comment

Ok, Your answer is good for my two questions...So I can do it:do python -c "('nohup <command> &') * 1" | bash and it should work

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.