1

有没有办法将 Linux 样式的 shell 替换转换为 Python 中的 Windows 替换?

假设在 Linux 环境中有一个命令:

my_command=cd
${my_command} .. OR $my_command .. resolves to cd ..

在 Windows 中:

SET my_command=cd
%my_command% .. resolves to cd ..

我想要它,如果我的环境是 Windows,那么我可以接受一个命令并将其替换为 Windows 样式替换:

样本输入/输出:

input: python myscript.py "${my_command}
output: "%my_command%"

谢谢!

4

1 回答 1

-2
for x in sys.argv:
    if x.startswith("$"):
       print "%%%s%%"%(x[1:])
于 2015-08-03T17:00:16.130 回答