此脚本用于 Arduino IDE 的 install.sh 文件:
sed -e "s,<BINARY_LOCATION>,\"${SCRIPT_PATH}/arduino\",g" \
-e "s,<ICON_NAME>,${RESOURCE_NAME},g" "${SCRIPT_PATH}/lib/desktop.template" > "${TMP_DIR}/${RESOURCE_NAME}.desktop"
该文件来自 Linux 64 位发行版 1.8.12(当前,2020 年 4 月)的 tarball。
逗号有什么作用?有没有人对 sed 和 regex 在所有情况下的逗号功能有很好的引用?
以下是我如何分解命令和我一直在搜索的所有地方。网络上有很多关于如何处理包含逗号的信息或向信息添加逗号的引用资料。逗号的功能不太容易找到。搜索“,”或“逗号”并没有让我走得很远。此堆栈溢出问题旨在添加某人可以找到的搜索结果。我的兴趣是学术。
***edit note: some of this is wrong. see answer from wjandrea for
corrections
sed - stream editor for filtering and transforming text (1)
-e script, --expression=script
add the following script to the commands to be executed (1)
s substitution
Its basic concept is simple: the s command attempts to match
the pattern space against the supplied regular expression
regexp; if the match is successful, then that portion of the
pattern space which was matched is replaced with replacement(2,3)
, ???
<> RegExpression for \< match beginning of word \> end of word (4)
$ Match the last line.
To ALLOW the Unix shell to interpret the dollar sign, put the
script in double quotes. sed "s/_terminal-type_/$TERM/g" (5)
{} A group of commands may be enclosed between { and } characters.
This is particularly useful when you want a group of commands
to be triggered by a single address (or address-range) match.(6)
g Copy/append hold space to pattern space. (1) Replace the
contents of the pattern space with the contents of the hold
space. (7) - find "Special Applications:"
最佳答案
在sed中, s
后面的字符用作分隔符。斜线 /
是标准。
The
/
characters may be uniformly replaced by any other single character within any givens
command.
Arduino 脚本可能使用备用分隔符来避免在
$SCRIPT_PATH
中转义斜杠, 也不太可能包含逗号。相比:s/<BINARY_LOCATION>/\/some\/path\/arduino/
s,<BINARY_LOCATION>,/some/path/arduino,
也可以使用逗号:
2,5d
a
的:/a\{2,5\}/
, 5 个或更多:/a\{5,\}/
顺便说一句,您崩溃的后半部分还很遥远。这是一个更正:
${SCRIPT_PATH}
代表一个变量 <>
- 这些都是字面意思。你在想 \<\>
g
- “全局” - 标志 s
:Apply the replacement to all matches to the regexp, not just the first.
关于regex - sed 和 regex 中逗号 ","的所有含义是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61512558/