dragora-members
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Dragora-members] Qi 2.0rc14


From: Matias Fonzo
Subject: Re: [Dragora-members] Qi 2.0rc14
Date: Sat, 01 Aug 2020 01:27:31 -0300
User-agent: Roundcube Webmail/1.4.6

El 2020-07-31 09:37, Michael Siegel escribió:
Am 31.07.20 um 03:29 schrieb Matias Fonzo:

UPDATE: I replaced the current lines with a printf ala:

printf '%s\n' \
"
Usage: $PROGRAM COMMAND [OPTIONS] [FILE]...
A simple but well-integrated package manager.

Defaults for the options are specified in brackets.

List of commands:
...
"

So much for the need of an external command and the use of heredoc...  :-)

Well, you've just introduced a subtle way to shoot yourself in the foot
because now, every double quote that ever enters that help text better
be escaped with a backslash.

Using a heredoc – and that would mean using cat(1) – would avoid this
problem entirely.

So, let me repeat:

1. Speed is not of importance for printing help text. Therefore, using
     an external command – cat(1), which is part of POSIX – is fine.
     After all, making use of external commands is largely what Unix
     shells are built for.
  2. Heredocs are safe because they are interpreted as literal strings
     entirely (using a single-quoted delimiter).
  3. printf is not safe for this.

So, I would really go with cat(1) and a heredoc. It's less code and it
is actually more reliable than the current solution.


I agree with the speed is not important for printing the help text. While cat(1) is defined by POSIX, printf, too.

Note: Using single-quotes makes the value of the variables not expand, but this is not a problem right now, as I have removed it. It's better this way since the change was made so that the configuration file is imported (instead of being parsed), and since the script can reflect values that come from the configuration file, well...

My thinking is a little more extreme and paranoid about it since:

- cat(1) is an external command: If this command is not available for some reason, goodbye to printing help.

- Here documents have tmpfile penalty: Behind the scenes in the shell it creates a temporary file every << here document. Then opens it and redirects the input from it. And removes it after it is done.

...





reply via email to

[Prev in Thread] Current Thread [Next in Thread]