[英]execute one line of python with variable input from bash
I want to write one line of python and wrap in such a way than it will run from bash.我想写一行 python 并以一种从 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:但是,我想要一个变量输入,所以我尝试将 pipe 之一输入,但以下不起作用:
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?我能做些什么来保持简单,保持一行,并添加一个变量输入?
You could do:你可以这样做:
i=5; python -c "print('my favorite number to itself is '+str($i**$i))"
With xargs:使用 xargs:
echo 5 | xargs -I {} python -c "print('my favorite number to itself is '+str({}**{}))"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.