You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The examples on globs in Tutorial.md is, as far as I can tell, wrong.
[ -f *foo* ] will do glob-matching, that is, if there is a single file in CWD with foo as a substring, this will pass. If there are more, it will (hopefully) just lead to an error "too many arguments". (Ie. don't do this.)
if [[ "${value}" =~ ".*$name.*" ]]; then
echo 'Yo dawg, we heard you like globs'
fi
will only match if value actually has literal quotes, and will, because of the literal quotes (at least on my machine) make the .* not be interpreted as a regex.
[[ is a bash built-in, while [ is a binary in /usr/bin (to complicate things, technically, bash defines [ as a built-in with the same semantics as the command …)
The examples on globs in Tutorial.md is, as far as I can tell, wrong.
[ -f *foo* ]
will do glob-matching, that is, if there is a single file in CWD withfoo
as a substring, this will pass. If there are more, it will (hopefully) just lead to an error "too many arguments". (Ie. don't do this.)will only match if
value
actually has literal quotes, and will, because of the literal quotes (at least on my machine) make the.*
not be interpreted as a regex.[[
is a bash built-in, while[
is a binary in /usr/bin (to complicate things, technically, bash defines[
as a built-in with the same semantics as the command …)[[
doesn't require quoted arguments:and as the regex example shows, they can (on the rhs of
=~
) mess things up.Run http://www.shellcheck.net/ (has an emacs flycheck plugin if you're of that persuasion) – it catches these things.
The text was updated successfully, but these errors were encountered: