1、有時候只是簡單的獲取下時間戳,不想在python解釋器的交互模式下再去執行python代碼,如何實現呢?python
以循環輸出多行爲例: (1)第一種方式: python -c "exec(\"import sys\nfor r in range(3): print 'arun'\")" arun arun arun (2)第二種方式: (echo "import sys" ; echo "for r in range(3): print 'arun'") | python arun arun arun
2、實踐bash
showtime () { ( echo "import datetime" echo 'print str(datetime.datetime.now()).split(".")[0].replace("-","").replace(":","").replace(" ","")' ) | python }
效果以下:blog
showtime 20190302100502