[GTALUG] Script to show HTTP(S) and TLS details for a website

Giles Orr gilesorr at gmail.com
Mon Sep 16 09:21:45 EDT 2019


On Sun, 15 Sep 2019 at 11:01, William Park via talk <talk at gtalug.org> wrote:

> On Sat, Sep 14, 2019 at 10:02:46AM -0400, D. Hugh Redelmeier via talk
> wrote:
> > | From: William Park via talk <talk at gtalug.org>
> >
> > | Hmm, minor personal irritant about variable assigment:
> > |     var=$(...)
> > | is enough.  You don't need to do
> > |     var="$(...)"
> >
> > I think that getting quotes right in sh is hard.  I support the
> > simplest rule that works:
> >
> > Always double-quote a $ thing UNLESS it must not be quoted.
> >
> > The case you point out may be quoted, so I would quote it.
>
> Extra quotes distract your eyes, makes it difficult to read or spot a
> bug.  It's like always carrying an opened umbrella (because you can),
> when you should do it only when it rains.
>

We covered this the first time I posted about the script - clearly there
are some strongly held opinions on the subject.  I'm going to state mine
once.

If you have a variable called "a" and another called "ab" and you type
"$ab" the shell script, you'll get the contents of variable "ab" not the
contents of variable "a" followed by the letter "b".  So I _always_ put
braces around my variable names - even though it's a pain to type and not
particularly beautiful.  It's syntactically correct and I won't ever get an
unexpected error.

My thinking is the same about quoting.

    filename="/var/log/apache.log"
    cat $filename

(Never mind it's a contrived example.)  That works just fine.  I didn't
brace or quote $filename.  And - as I said last time - everything goes
swimmingly right up until someone edits your file, or gives it some input
such that the filename variable includes a space.  And then - if you're
lucky - you get a "file not found" error, but depending on your code the
error may be much more obscure.  Which is bad enough if you have to dig out
the error, and far worse if the script is in the hands of someone who has
no Bash knowledge.

I choose to use the quotes and braces as a precaution against possible
future problems.  Some people don't, and that's fine.  But what I'm doing
isn't "wrong" (it's valid and safe syntax), so I don't think it's worth a
lot of debate.

-- 
Giles
https://www.gilesorr.com/
gilesorr at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://gtalug.org/pipermail/talk/attachments/20190916/a20dbbe6/attachment.html>


More information about the talk mailing list