我想写一行python,并以比bash运行的更好的方式包装。我研究了它,这个想法似乎是可能的,但是,我特别想加入一个变量输入。
作为一个说明性的例子,以下是行之有效的方法:
python -c "print('my favorite number to itself is '+str(5**5))"但是,我希望有一个变量输入,所以我尝试输入一个变量,但是下面的内容不起作用:
5 | python -c "print('my favorite number to itself is '+str($1**$1))"我能做些什么来保持它简单,保持一行,并添加一个变量输入?
发布于 2019-09-22 01:36:20
你可以这样做:
i=5; python -c "print('my favorite number to itself is '+str($i**$i))"发布于 2019-09-22 01:43:10
用xargs:
echo 5 | xargs -I {} python -c "print('my favorite number to itself is '+str({}**{}))"https://stackoverflow.com/questions/58045359
复制相似问题