- 论坛徽章:
- 0
|
本帖最后由 thyswallow 于 2011-01-05 23:26 编辑
想用"perl -pi -e"使用正则表达式匹配并替换文件中的特殊字符,在 sh中工作正常,但是在 csh中,虽然替换成功,但是总是出现一些额外的信息。
Eg, 替换临时文件中的password, 将12345 替换成 xxxx.
1.tmpfile
============================================
isql -Upxedbo -P12345 -SLON_PXE_UAT -DPXE -iCMG22546.sql
============================================
替换后的文件应为:isql -Upxedbo -Pxxxx -SLON_PXE_UAT -DPXE -iCMG22546.sql
2. Script
============================================
#!/bin/csh
grep -i "isql" tmpfile > /dev/null
if ( $status == 0 ) then
echo "matched"
`perl -pi -e "s/(.*) -P(.*) (.*)/\1 -Pxxxx \3/" tmpfile`
else
echo "don't match"
endif
============================================
3. Run
>./testfile2
matched
/usr/openwin/bin/: Permission denied
>
4. Problem
运行后, tmpfile文件中的12345被正确替换成了xxxx, 但是出现
/usr/openwin/bin/: Permission denied。
如果使用#!/bin/sh,就不会出现这样的信息。
而且在不同的机器上运行,有时会出现不同的信息。
/usr/local/bin/: Permission denied
觉得很蹊跷,请指点。 |
|