[英]Bash script in-braces weird escaping and pound symbol
I'm reading a bash script function which takes an input variable with escape codes as first parameter and cycles on its characters, anyway I can't understand these lines:我正在阅读一个 bash 脚本函数,该函数将带有转义码的输入变量作为第一个参数并循环其字符,无论如何我无法理解这些行:
local input="${1//\"/\\\"}" output="" i char within_code=0
for ((i=0; i < ${#input}; ++i)); do
char="${input:i:1}" # get current character
I guess my bash-foo isn't strong enough.我想我的 bash-foo 不够强大。
"${1//\\"/\\\\\\"}"
?什么是"${1//\\"/\\\\\\"}"
? The first parameter should be $1
I think.我认为第一个参数应该是$1
。#
in ${#input}
do? ${#input}
中的#
什么作用?The rest I can, more or less, understand.其余的我或多或少能理解。
The expansions are explained in the bash manual Shell Parameter Expansion . bash 手册 Shell Parameter Expansion中解释了这些扩展。
"
with \\"
in $1
.它将$1
所有出现的"
替换为\\"
。 Yes, $1
expands to the first positional parameter.是的, $1
扩展到第一个位置参数。${#input}
expands to the length of $input
. ${#input}
扩展到$input
的长度。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.