Path: csiph.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Ralf Fassel Newsgroups: comp.os.linux.misc Subject: Re: correct quoting for variables in bash scripts? Date: Tue, 18 Oct 2022 11:31:11 +0200 Lines: 26 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain X-Trace: individual.net MtpYbseIDS6Fw/4Ph0G6KA1SXG+zYp/z149fO3rQekUKsKdYI= Cancel-Lock: sha1:78Hh6TdjE+JGi+Oa7g9oAbwtYDI= sha1:9zr9sYDeyKx/VzSYtd6vQOt1nm0= User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux) Xref: csiph.com comp.os.linux.misc:35740 * Eli the Bearded <*@eli.users.panix.com> | In your example neither is needed. Firstly there's nothing adjoining to | confuse the variable name. Secondly, it is [[ not [. > | The one [ ] square bracket form of the test command needs empty string | protection because variable expansion happens before thecommand is run. > | The two [[ ]] square bracket form of the test command is explicitly a | shell built-in, so it can recognize empty strings without help. Interesting, didn't know that difference: $ unset bar $ [[ $bar = x ]] && echo yes $ type [[ [[ is a shell keyword $ [ $bar = x ] && echo yes bash: [: =: unary operator expected $ type [ [ is a shell builtin Most probably the error thrown with "[" is to ensure compatibility with /usr/bin/test? R'