简体   繁体   中英

Using double quotes in a command assigning it in a variable with double quotes bash

dir="$(find -L "${1:-.}" -mindepth 1 -type d 2>/dev/null|fzf -0)"

why it works even if quoting end is unspecified in bash. This should've show error but worked perfectly.WHY?

Previously I tried dir="$(find -L \"${1:-.}\" -mindepth 1 -type d 2>/dev/null|fzf -0)" but it failed.

$(...) establishes a new quoting context. After the $( , the next " is an opening quote, not the closing quote paired with your opening quote before the $( .

As the entire right-hand side is a single command substitution, you don't need the outer quotes at all, as the RHS is not subject to word-splitting or pathname expansion, the prevention of which are the two reasons you would otherwise quote it.

dir=$(find -L "${1:-.}" -mindepth 1 -type d 2>/dev/null | fzf -0)

is sufficient.

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