Scripting problem

Cameron Simpson cs at cskk.id.au
Tue Oct 10 11:19:13 UTC 2017


On 08Oct2017 09:54, Polytropon <freebsd at edvax.de> wrote:
>On Sun, 08 Oct 2017 00:59:39 -0500, Paul Schmehl wrote:
>> I'm having a problem with this line:
>> /usr/local/bin/mutt -s $SUBJECT -i $MESSAGE -a $FILENAME --
>> pschmehl at tx.rr.com < /dev/null

Your variable substitutions are not quoted, as mentioned. That is critical. The 
shell is a tool for assembling command string arrays, and quoting is used to 
demark single strings.

[...]
>This proves you have a quoting problem. Enclose the parameters
>in the mutt call in "...", like this:
>
>	/usr/local/bin/mutt -s "$SUBJECT" -i "$MESSAGE" -a "$FILENAME" -- pschmehl at tx.rr.com < /dev/null
>
>When the variables are being evaluated by the shell, the quotes
>during assignment are removed, and you you get is
>
>	/usr/local/bin/mutt -s Today's db backup -i path/to/message.txt -a /whatever/filename/there.is -- pschmehl at tx.rr.com < /dev/null
>
>The unterminated ' is handled more or less gracefully, but it
>probably interferes with mutt's address detection. You can
>now easily recognize the problem.

No, mutt noever considers it for addresses, because it is the subject string.  
There's no "more or less gracefully", it is just a string.

The mutt command is invoked as an array of strings, thus (one per line):

    /usr/local/bin/mutt
    -s
    Today's db backup
    -i
    path/to/message.txt
    -a
    /whatever/filename/there.is
    --
    pschmehl at tx.rr.com

There is no subsequent parsing or weird interpretation.

>> I'm running FreeBSD 10.3-RELEASE and the script is written in bash.

Just say "/bin/sh". It may be implemented by bash on your system, but it is 
generally the Bourne shell. Nothing you're doing requires bash itself, but all 
UNIX systems have /bin/sh.

>Do you have any reasons not to stick to default sh? Do you use
>any features specific to bash?

Ah, I see this has also been maddresses.

Cheers,
Cameron Simpson <cs at cskk.id.au> (formerly cs at zip.com.au)


More information about the freebsd-questions mailing list