我使用 sed 尝试了以下 PowerShell 脚本:
[array declarations]
Foreach ($var in $double)
{
$command = $command + " -e "
$command = $command + "s/$var/sMOS3double\[$var\]\[index\]/"
}
$command = $command + " mos3load_fun_09052012.c > poZamianie.txt"
**echo $command**
sed $command
不幸的是,它返回错误:
**./Renamer.ps1**
-e 's/vds/sMOS3double\[vds\]\[index\]/' -e 's/vbs/sMOS3double\[vbs\]\[index\]/' -e 's/vgs/sMOS3double\[vgs\]\[index\]/
' -e 's/vbd/sMOS3double\[vbd\]\[index\]/' -e 's/vgd/sMOS3double\[vgd\]\[index\]/' -e 's/vt/sMOS3double\[vt\]\[index\]/'
-e 's/EffectiveWidth/sMOS3double\[EffectiveWidth\]\[index\]/' -e 's/EffectiveLength/sMOS3double\[EffectiveLength\]\[in
dex\]/' -e 's/OxideCap/sMOS3double\[OxideCap\]\[index\]/' -e 's/Beta/sMOS3double\[Beta\]\[index\]/' -e 's/cdrain/sMOS3d
ouble\[cdrain\]\[index\]/' -e 's/vdsat/sMOS3double\[vdsat\]\[index\]/' -e 's/von/sMOS3double\[von\]\[index\]/' mos3load
_fun_09052012.c > poZamianie.txt
**sed.exe: -e expression #1, char 2: unknown command: `-'**
我努力尝试,使用 ''、"" 或根本没有分隔符的配置,但没有成功。
但是,然后我从 PS 控制台复制了回显输出,并再次将其作为参数传递给控制台:
**sed** -e s/vds/sMOS3double\[vds\]\[index\]
/ -e s/vbs/sMOS3double\[vbs\]\[index\]/ -e s/vgs/sMOS3double\[vgs\]\[index\]/ -e s/vbd/sMOS3double\[vbd\]\[index\]/ -e s
/vgd/sMOS3double\[vgd\]\[index\]/ -e s/vt/sMOS3double\[vt\]\[index\]/ -e s/EffectiveWidth/sMOS3double\[EffectiveWidth\]\
[index\]/ -e s/EffectiveLength/sMOS3double\[EffectiveLength\]\[index\]/ -e s/OxideCap/sMOS3double\[OxideCap\]\[inde\]/ -
e s/Beta/sMOS3double\[Beta\]\[index\]/ -e s/cdrain/sMOS3double\[cdrain\]\[index\]/ -e s/vdsat/sMOS3double\[vdsat\]\[inde
x\]/ -e s/von/sMOS3double\[von\]\[index\]/ mos3load_fun_09052012.c > poZamianie.txt
脚本正确执行。
任何人都可以解释这种行为吗?或者展示一种直接使用 PowerShell 执行该脚本的方法?