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

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

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.

AIUI the Bourne shell interpolates variables, and potentially other constructs, within double-quotes. I avoid double quotes unless I want interpolation.


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...

I find that a version control system can be very useful for system administration, by allowing me to check in and verify all of my configuration files, scripts, etc..


David


Reply to: