【问题标题】:Replacing smart quotes in unix with single quotes using sed on LInux Suse 12在 LInux Suse 12 上使用 sed 将 unix 中的智能引号替换为单引号
【发布时间】:2020-03-30 23:10:52
【问题描述】:

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

#!/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

【问题讨论】:

  • 您使用的是什么字符集?你的smart quote在我看来就像斯堪的纳维亚的a,上面有小o的那个。
  • cron下locale的输出是什么? Vs 通常是什么?
  • 在 Windows 中,有问题的注释行是
  • 啊哈通常是 LC_CTYPE="POSIX" 但作为 cron 它是 en_US.UTF-8

标签: linux sed replace cron quotes


【解决方案1】:

我加了

LC_CTYPE="POSIX"

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

我不知道 locale 命令,谢谢 o11c

【讨论】:

    猜你喜欢
    • 2014-03-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-14
    • 2017-08-05
    • 2020-12-23
    • 2020-03-27
    • 2011-10-21
    相关资源
    最近更新 更多