【发布时间】:2020-08-02 21:25:22
【问题描述】:
在终端 shell 中,我试图遍历一组 Python 文件并使用 sed 执行查找和替换,例如:
$ for f in `ls *.py`; do sed -i 's|foo|bar|g' $f; done;
但是,对于某些文件(尤其是那些我已更改为可执行的 Python 脚本),它会给出错误:
sed: can't read example_script.py: No such file or directory
为什么它可能不适用于可执行文件,但适用于其他文件?
【问题讨论】:
-
Why not parse
ls?。使用for f in *.py; do。 -
为什么在这种情况下使用
ls?