Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.debian.user > #228001

Re: rsync --delete

From David Christensen <dpchrist@holgerdanske.com>
Newsgroups linux.debian.user
Subject Re: rsync --delete
Date 2020-10-20 05:20 +0200
Message-ID <B1QlQ-3Rv-3@gated-at.bofh.it> (permalink)
References <B0Gox-2vP-7@gated-at.bofh.it> <B12yK-7sb-13@gated-at.bofh.it> <B1BZw-3oQ-13@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On 2020-10-19 04:55, Greg Wooledge wrote:
> On Sat, Oct 17, 2020 at 03:01:13PM -0700, David Christensen wrote:
>> I try to use all lower case letters for variable names and all upper case
>> letters for constants.
> 
> ALL_UPPER_CASE is reserved for internal shell variables, and environment
> variables.

Please provide a citation (for Bourne shell scripts).


> If you abuse it for "constants" as well, on your head be it.  You must
> take care to ensure that your ALL_CAPS variable does not collide with
> any internal shell variables, or environment variables.

Yes.


>> I use braces whenever evaluating a variable -- '${Params}'.  I forget the
>> details why, but I do recall that this practice is important.
> 
> It isn't.  It's entirely stylistic.

https://stackoverflow.com/questions/8748831/when-do-we-need-curly-braces-around-shell-variables


>> I don't use Bourne arrays, and I barely understand how the shell
> 
> Bourne shell does not have arrays.  Neither does POSIX shell.
> 
>> interpolates lists and preserves items containing whitespace.  When I can't
>> figure it out, I switch to Perl.
> 
> OK.

No wonder I don't use arrays (or Bash) in shell scripts.


>>> cd /home/mike
>>
>> I prefer scripts that I can run from anywhere.
> 
> ... hence, the cd inside the script.  Doesn't matter where you call it
> from, as long as the script cd's to the right location to do its work,
> **AND VERIFIES THAT THE cd ACTUALLY WORKED**.

Another reason why I use 'set -e':

2020-10-19 20:06:06 dpchrist@tinkywinky ~/sandbox/sh
$ cat /etc/debian_version ; uname -a
9.13
Linux tinkywinky 4.9.0-13-amd64 #1 SMP Debian 4.9.228-1 (2020-07-05) 
x86_64 GNU/Linux

2020-10-19 20:06:08 dpchrist@tinkywinky ~/sandbox/sh
$ cat set-e.sh
#!/bin/sh
set -x
cd /no/such/directory
echo $?
set -e
cd /another/bad/directory
echo $?

2020-10-19 20:06:14 dpchrist@tinkywinky ~/sandbox/sh
$ /bin/sh set-e.sh
+ cd /no/such/directory
set-e.sh: 3: cd: can't cd to /no/such/directory
+ echo 2
2
+ set -e
+ cd /another/bad/directory
set-e.sh: 6: cd: can't cd to /another/bad/directory


>> If the script must change the working directory, I would display that --
>> 'set -x', 'cd ...', and 'set +x'.
> 
> For god's sake, why?

Sometimes I debug a script by opening another terminal and entering the 
commands that the script executed.

Sometimes I tee(1) the output of script to a log file so I have a record 
of what the script did.


>> I use 'set -e'
> 
> NOOOOOOOOOOO!!!!

On 2020-10-19 12:16, Greg Wooledge wrote:

 > https://mywiki.wooledge.org/BashFAQ/105

I am sorry, but your article does not convince me to not set 'errexit' 
in my Bourne shell scripts.  If and when I do need to deal with exit 
values manually, I will disable 'errexit' for the relevant stretch of 
code and then re-enable errexit afterwards.


On 2020-10-19 05:00, Greg Wooledge wrote:
 > using an explicit /usr/bin/rsync is sketchy at best.  You
 > should already have /usr/bin in your PATH

AIUI using absolute paths for tools in shell scripts is a security best 
practice -- it helps defend against attacks where PATH is compromised 
and/or trojaned system tools are inserted into directories at the front 
of PATH.

Using absolute paths for tools also means that the script will work when 
cron(8) runs it (or runs something that runs it).


David

Back to linux.debian.user | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

rsync --delete Mike McClain <mike.junk.46@att.net> - 2020-10-17 00:30 +0200
  Re: rsync --delete Klaus Singvogel <deb-user-ml@singvogel.net> - 2020-10-17 00:40 +0200
    Re: rsync --delete Greg Wooledge <wooledg@eeg.ccf.org> - 2020-10-19 13:40 +0200
  Re: rsync --delete ellanios82 <ellanios82@gmail.com> - 2020-10-17 00:40 +0200
  Re: rsync --delete Charles Curley <charlescurley@charlescurley.com> - 2020-10-17 04:10 +0200
  Re: rsync --delete Will Mengarini <seldon@eskimo.com> - 2020-10-17 08:40 +0200
    Re: rsync --delete Greg Wooledge <wooledg@eeg.ccf.org> - 2020-10-19 13:50 +0200
  Re: rsync --delete <tomas@tuxteam.de> - 2020-10-17 10:40 +0200
    Re: rsync --delete David <bouncingcats@gmail.com> - 2020-10-17 14:20 +0200
      Re: rsync --delete <tomas@tuxteam.de> - 2020-10-17 15:30 +0200
    Re: rsync --delete Mike McClain <mike.junk.46@att.net> - 2020-10-17 20:30 +0200
      Re: rsync --delete Greg Wooledge <wooledg@eeg.ccf.org> - 2020-10-19 13:50 +0200
    Re: rsync --delete Andrei POPESCU <andreimpopescu@gmail.com> - 2020-10-18 12:50 +0200
  Re: rsync --delete Andy Smith <andy@strugglers.net> - 2020-10-17 17:30 +0200
  Re: rsync --delete David Christensen <dpchrist@holgerdanske.com> - 2020-10-18 00:10 +0200
    Re: rsync --delete Mike McClain <mike.junk.46@att.net> - 2020-10-19 01:40 +0200
    Re: rsync --delete Greg Wooledge <wooledg@eeg.ccf.org> - 2020-10-19 14:00 +0200
      Re: rsync --delete Mike McClain <mike.junk.46@att.net> - 2020-10-19 21:10 +0200
        Re: rsync --delete Greg Wooledge <wooledg@eeg.ccf.org> - 2020-10-19 21:20 +0200
          Re: rsync --delete Tixy <tixy@yxit.co.uk> - 2020-10-19 23:20 +0200
            Re: rsync --delete David Christensen <dpchrist@holgerdanske.com> - 2020-10-20 05:10 +0200
              Re: rsync --delete Tixy <tixy@yxit.co.uk> - 2020-10-20 09:30 +0200
                Re: rsync --delete David <bouncingcats@gmail.com> - 2020-10-20 10:00 +0200
                Re: rsync --delete Tixy <tixy@yxit.co.uk> - 2020-10-20 10:20 +0200
              Re: rsync --delete Andrei POPESCU <andreimpopescu@gmail.com> - 2020-10-20 11:10 +0200
        Re: rsync --delete David <bouncingcats@gmail.com> - 2020-10-19 23:20 +0200
      Re: rsync --delete David Christensen <dpchrist@holgerdanske.com> - 2020-10-20 05:20 +0200
        Re: rsync --delete David <bouncingcats@gmail.com> - 2020-10-20 06:10 +0200
          Re: rsync --delete Nicolas George <george@nsup.org> - 2020-10-20 12:10 +0200
        Re: rsync --delete Greg Wooledge <wooledg@eeg.ccf.org> - 2020-10-20 13:50 +0200
          Re: rsync --delete The Wanderer <wanderer@fastmail.fm> - 2020-10-20 14:50 +0200
            Re: rsync --delete Greg Wooledge <wooledg@eeg.ccf.org> - 2020-10-20 15:10 +0200
              Re: rsync --delete The Wanderer <wanderer@fastmail.fm> - 2020-10-20 15:50 +0200
                Re: rsync --delete Greg Wooledge <wooledg@eeg.ccf.org> - 2020-10-20 16:10 +0200
    define (or translate, or substitute for) "interpolate": Re: rsync --delete rhkramer@gmail.com - 2020-10-19 14:30 +0200
      Re: define (or translate, or substitute for) "interpolate": Re: rsync --delete rhkramer@gmail.com - 2020-10-19 14:50 +0200
      Re: define (or translate, or substitute for) "interpolate": Re:  rsync --delete <tomas@tuxteam.de> - 2020-10-19 15:00 +0200
        Re: define (or translate, or substitute for) "interpolate": Re: rsync --delete rhkramer@gmail.com - 2020-10-20 02:10 +0200
          Re: define (or translate, or substitute for) "interpolate": Re: rsync  --delete David Christensen <dpchrist@holgerdanske.com> - 2020-10-20 05:50 +0200
  Re: rsync --delete Greg Wooledge <wooledg@eeg.ccf.org> - 2020-10-19 14:10 +0200

csiph-web