linux - 在 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
解决方案
我添加了
LC_CTYPE="POSIX"
到我的脚本,现在两种解决方案在是否以 cron 运行时都可以正常工作!
我不知道 locale 命令感谢 o11c
推荐阅读
- reactjs - 如何检查 React 是否更新 dom?
- angular - Angular - 声明嵌套的接口对象数组
- php - 如何在 PHP 中将多个数字循环在一起?
- jakarta-ee - 将 kotlin-compiler-embeddable 嵌入 Java EE App 会导致 CDI 相关的部署错误
- python - 循环未正确对值求和
- excel - 从 Excel 获取图表/图形到 Matlab 报告生成器
- python - Python - 比较两个列表时出现循环问题
- swift - MobileVLCKit 在项目中占用了大量空间
- python - 添加多列
- java - 是否可以通过配置文件激活或停用作业以避免意外启动?