[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 22:55, David Christensen wrote:
On 2020-09-20 18:18, Gary Dale wrote:
On 2020-09-20 20:36, David Christensen wrote:

The environments are identical.

Have you tried '#!/bin/sh' ?

That's my shebang line.

Have you tried single quotes?

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

Double quotes, single quotes, and no quotes have the same behavior on my machine:

2020-09-20 19:50:55 dpchrist@tinkywinky ~/sandbox/sh
$ cat debian-user-20200920-1727-gary-dale.sh
#!/bin/sh

doublequote="/root/clamscan-report"
echo $doublequote

singlequote='/root/clamscan-report'
echo $singlequote

noquote='/root/clamscan-report'
echo $noquote

2020-09-20 19:53:02 dpchrist@tinkywinky ~/sandbox/sh
$ /bin/sh -x debian-user-20200920-1727-gary-dale.sh
+ doublequote=/root/clamscan-report
+ echo /root/clamscan-report
/root/clamscan-report
+ singlequote=/root/clamscan-report
+ echo /root/clamscan-report
/root/clamscan-report
+ noquote=/root/clamscan-report
+ echo /root/clamscan-report
/root/clamscan-report


Please run the above script and the following commands, and post your console session -- prompts, commands, output:

2020-09-20 19:52:29 dpchrist@tinkywinky ~/sandbox/sh
$ cat /etc/debian_version
9.13

2020-09-20 19:52:38 dpchrist@tinkywinky ~/sandbox/sh
$ uname -a
Linux tinkywinky 4.9.0-13-amd64 #1 SMP Debian 4.9.228-1 (2020-07-05) x86_64 GNU/Linux

2020-09-20 19:52:43 dpchrist@tinkywinky ~/sandbox/sh
$ dpkg-query --show dash
dash    0.5.8-2.4

2020-09-20 19:52:51 dpchrist@tinkywinky ~/sandbox/sh
$ dpkg --verify dash

2020-09-20 19:52:56 dpchrist@tinkywinky ~/sandbox/sh
$ sha256sum /bin/sh
e803088e7938b328b0511957dcd0dd7b5600ec1940010c64dbd3814e3d75495f /bin/sh


David

In the simple case, the quotes are the same, but there are times when they have different behaviours. I avoid single-quotes so that when I use them, it's a clue that there is a reason.

Here's what I got with your script:

/root/clamscan-report
/root/clamscan-report
/root/clamscan-report

When I retried my script with the quotes, it started working. I have no idea what changed from earlier today. I certainly didn't update anything on either server...


Reply to: