When I type python in a shell I get >>> as a result. Then if I type print "something", it prints something. I want to do both in a single command via bash script. Here is an example that doesn't work but is close to getting the point across
`print "something"` | python;
I would expect python to be executed and the print command to be passed as an argument. But this is not the case.
How can I do this:
python
>>> print "hello"
in one command?
John Kugelman
365k70 gold badges555 silver badges600 bronze badges
asked Apr 11, 2013 at 3:45
user1869582
4791 gold badge4 silver badges10 bronze badges
2 Answers 2
How about:
python -c "print 'hello'"
answered Apr 11, 2013 at 3:47
Sajjan Singh
2,5612 gold badges28 silver badges35 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
You would need to write it as
echo 'print "something"' | python
or
printf 'print "something"' | python
but Bhajun's answer is what you really want.
answered Apr 11, 2013 at 12:46
chepner
538k77 gold badges596 silver badges747 bronze badges
Comments
lang-bash