python -c參數,支持執行單行命令/腳本。
例:
> python -c "import os;print('hello'),print('world')" > python -c "import os;print('hello');print('world')"
注意:要用雙引號將命令包起來,import要以**;結尾,命令用[]括起來,多行命令用多個[]**
> python -c "import os,time;[print(i) for i in os.listdir()];[print(time.time())]" > python -c "import os,time;[print(i) for i in os.listdir()],[print(time.time())]"
復雜的命令必須要用**[]**括起來,否則會報錯。
格式上還可以多嘗試一下:
> python -c "print('hello');print('world')" > python -c "print('hello'),print('world')" > python -c "[print('hello'),print('world')]" > python -c "[print('hello')],[print('world')]"
這幾條的輸出是一樣的。
以上。
————————————————
版權聲明:本文為CSDN博主「phoenix339」的原創文章,遵循 CC 4.0 BY-SA 版權協議,轉載請附上原文出處鏈接及本聲明。
原文鏈接:https://blog.csdn.net/phoenix339/article/details/90405610