BASH: sed 从 $STRING 中删除“/”

BASH: sed to remove "/" from a $STRING

首先让我为提出一个问题而道歉:

问题:

我想为我正在编写的脚本替换 bash 中 $STRING 中的文本。我选择合并 date/time 以允许更轻松的最终用户集成。

STARTTIME="2015-03-17/11:30:00"
sed "Unknown"

尝试的解决方案:

sed '/s// /' "$STARTTIME"

期望的结果是删除“/”并以 2015-03-17 11:30:00 结束,然后传递给命令。

感谢您的帮助。

如果您使用 bash,我建议您使用内置 string manipulation:

$ s='2015-03-17/11:30:00'
$ echo "${s/\// }"
2015-03-17 11:30:00

大括号内的语法表示"replace the first occurrence of a forward slash (which needs escaping) with a space".