Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use python in shell, as if it were awk

Tags:

python

shell

awk

Say I want to print 1 + 1 on stdout (i.e. one-liner coding).

With awk I could do it simply with:

$ echo | awk '{print 1+1}'
2

How to do this with python?

like image 325
cregox Avatar asked May 23 '26 10:05

cregox


1 Answers

you are looking for -c:

$ python -c 'print 1 + 1'
2
like image 117
SingleNegationElimination Avatar answered May 24 '26 23:05

SingleNegationElimination



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!