首页 > 解决方案 > 在 LInux Suse 12 上使用 sed 将 unix 中的智能引号替换为单引号

问题描述

如果我以普通用户身份运行它

#!/bin/bash
echo This is a smart quote â fixed using previous method | sed "s/â/'/g"
QUOTES="\xE2\x80\x9C|\xE2\x80\x9D"
echo This is a fixed smart quote â fixed using new method | sed "s/[$QUOTES]/'/g"

按预期在提示符处运行脚本时,使用任一方法替换智能引号

如果我将脚本作为 cron 作业运行,我会得到

sed: -e expression #1, char 7: unterminated `s' command

使用任何一种方法

为什么 sed 在 cron 中的运行方式不同?

在 Windows 中,有问题的注释行是:

FTX368 20/09/2012 VV 10798 - 添加“福利维护”按钮。

所以它是一个聪明的单引号 - ASCII 146 - Hex 92

标签: linuxsedreplacecronquotes

解决方案


我添加了

LC_CTYPE="POSIX"

到我的脚本,现在两种解决方案在是否以 cron 运行时都可以正常工作!

我不知道 locale 命令感谢 o11c


推荐阅读