我有下面的代码来替换多个文件中的一些字符串,但 for 循环正在检查第一个文件而不是执行 perl 脚本。下面是我的代码
if [ -f zebu.work.post_opt/ZEBU_CTO_FT_MOD.v ]
then
for file in $(./zebu.work.post_opt/ZEBU_CTO_FT_MOD*);
do
perl -i -p -e 's/input/inout/g' $file;
perl -i -p -e 's/output/inout/g' $file;
perl -i -p -e 's/wire.*\n/tran\(i0,\ o\);/g' $file;
perl -i -p -e 's/assign.*\n//g' $file;
done
fi
答案1
该$(foo)
构造将运行该命令foo
并替换$(foo)
为运行的输出foo
。你想要一个 glob,那不是命令。您正在做的是尝试运行所有名为./zebu.work.post_opt/ZEBU_CTO_FT_MOD*
.所有你需要的是:
if [ -f zebu.work.post_opt/ZEBU_CTO_FT_MOD.v ]
then
for file in ./zebu.work.post_opt/ZEBU_CTO_FT_MOD*;
do
perl -i -p -e 's/input/inout/g' "$file"
perl -i -p -e 's/output/inout/g' "$file"
perl -i -p -e 's/wire.*\n/tran\(i0,\ o\);/g' "$file"
perl -i -p -e 's/assign.*\n//g' "$file"
done
fi
或者,更简单地说:
if [ -f zebu.work.post_opt/ZEBU_CTO_FT_MOD.v ]
then
for file in ./zebu.work.post_opt/ZEBU_CTO_FT_MOD*;
do
perl -i -p -e 's/input/inout/g; s/output/inout/g;
s/wire.*\n/tran\(i0,\ o\);/g;
s/assign.*\n//g' "$file"
done
fi
或者更简单地说:
if [ -f zebu.work.post_opt/ZEBU_CTO_FT_MOD.v ]
then
perl -i -p -e 's/input/inout/g; s/output/inout/g;
s/wire.*\n/tran\(i0,\ o\);/g;
s/assign.*\n//g' ./zebu.work.post_opt/ZEBU_CTO_FT_MOD*
fi