python3 -c command [arg]
后面接要执行的python语句
举例
$ python3 -c 'print("Hello")'
Hello

python3 -m module [arg]
后面接一个模块及参数
$ python3 -m usescanner.py data.txt
Hello file world!

Bye  filel world.

$ cat usescanner.py 
#!/usr/local/bin/python
from sys import argv
from scanfile import scanner
filename = './data.txt'
filename = argv[1]
scanner(filename)

$ cat scanfile.py 
def scanner(name):
    file =  open(name,'r')
    while True:
        line =  file.readline()
        #if not
        if not line: break
        #function(line)
        print(line)
    file.close()
    
$ cat data.txt
Hello file world!
Bye  filel world.

bash命令的--rcfile参数,指定另一个脚本代替.bashrc。
cat ./scripts/dshell 
#!/bin/bash
DATA_DIR=`python3 -c "import dshell.util; print (dshell.util.get_data_path());"`
/bin/bash --rcfile "$DATA_DIR/dshellrc"

Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐