1

I want to write one line of python and wrap in such a way than it will run from bash. I looked into it and the idea seemd possible but, I'd specifically like to incorporate a variable input.

As an illustrative example; Here's what worked:

python -c "print('my favorite number to itself is '+str(5**5))"

However, I'd like to have a variable input so I tried to pipe one in, but the following doesn't work:

5 | python -c "print('my favorite number to itself is '+str($1**$1))"

What can I do to keep it simple, keep it one line, and add a variable input?

2 Answers 2

2

You could do:

i=5; python -c "print('my favorite number to itself is '+str($i**$i))"
Sign up to request clarification or add additional context in comments.

Comments

1

With xargs:

echo 5 | xargs -I {} python -c "print('my favorite number to itself is '+str({}**{}))"

Comments

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.