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

Re: weird behaviour of quotes in dash variable assignments



On 2020-09-20 20:36, David Christensen wrote:
On 2020-09-20 15:14, The Wanderer wrote:
On 2020-09-20 at 17:27, Gary Dale wrote:

I have the same bash script on two different Debian/Buster AMD64
servers. However on one it refused to run. I tracked it down quickly
to a variable substitution problem.

The line causing the problem reads: report="/root/clamscan-report"

On one server  echo $report  prints  /root/clamscan-report while on
the other it prints  "/root/clamscan-report".

Needless to say clamscan can't print to the latter. I fixed it by
removing the quotes on the one server but now the scripts are
different between the two servers, which isn't what I want.

Given the lack of spaces or other potentially-problematic characters in
the path, why not remove them on both servers? Will there potentially be
cases where the path is different, and such characters may be present?

More importantly, I don't understand why it refuses to remove the
quotes.

Where does this behaviour (keeping the quotes) get set?

First up: are you sure it's actually bash (rather than some other shell)
that's running the script in both cases?

Second, can you confirm that bash is the same version on both servers?
As reported by e.g 'bash --version'.

If both of those are confirmed, then it may be worth digging deeper. I'm
a bit reluctant to delve deep into the bash man page looking for
something like that without first ruling out other possibilities.

My first guess would be that one of the two might be using the shell
builtin command 'echo' and the other might be using /bin/echo, but
that's only a guess.

And:


Is the environment identical on the two servers?

    server1$ env > env1.out

    server2$ env > env2.out

    (move one file to the other host)

    $ diff env1.out env2.out


The environments are identical. The server uses are similar - both run Samba 4 and have Exim 4 set up for sending mail to me. Both run KVM virtual machines. The server that works also runs bacula and borg while the problem server runs NFS and Apache2.




Do you have a  "shebang" line as the first line of the script? Please post.


I find that Bourne syntax shell scripts are more portable than Bash syntax shell scripts.  Have you tried '#!/bin/sh' ?

That's my shebang line. /bin/sh in both cases is a symlink to dash (sorry, keep forgetting that Debian has been using dash instead of bash for years now). The version of dash is identical between the two servers.




Have you tried single quotes?

Wouldn't want to. Single quotes alter the behaviour.


Reply to: