作为临时解决方案,我决定猴子补丁plumbum
:shquote
from plumbum.cmd import split, seq, rev, dd
import plumbum
import unittest.mock as mock
# HACK: disable quoting of every argument in shquote
# otherwise we'd get --filter="dd 'of=$FILE'"
# which would create a file named $FILE anyway
with mock.patch('plumbum.commands.base.shquote', lambda x: x):
my_filter = str(rev | dd['of=$FILE'])
funnychars_new = plumbum.commands.base._funnychars.replace('$', '')
# HACK: don't treat dollar sign as an escapeable character
with mock.patch('plumbum.commands.base._funnychars', funnychars_new):
cmd = seq['1', '10'] | split['--filter', my_filter]
print(cmd)
cmd & plumbum.FG
把它放在命令执行之前为我解决了这个问题,但我欢迎另一个解决方案。