简体   繁体   中英

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:

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.

  • What is "${1//\\"/\\\\\\"}" ? The first parameter should be $1 I think.
  • What does the # in ${#input} do?

The rest I can, more or less, understand.

The expansions are explained in the bash manual Shell Parameter Expansion .

  1. It substitutes all occurrences of " with \\" in $1 . Yes, $1 expands to the first positional parameter.
  2. The ${#input} expands to the length of $input .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM