[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Using different options to run rsync
From: |
Greg Wooledge |
Subject: |
Re: Using different options to run rsync |
Date: |
Mon, 19 Jul 2021 08:55:13 -0400 |
On Mon, Jul 19, 2021 at 02:43:26PM +0200, lisa-asket@perso.be wrote:
> I am duplicating code here, all those -av, --progress, $source, $destin are
> the same in both branches.
>
> Perhaps it is best to avoid that. Since I am running `bash`, I could collect
> the arguments to an array.
That's certainly one possible choice.
> if (( filetr_dryrun == 1 )); then
>
> echo "rsync -av --progress --dry-run --log-file=$logfl"
> echo " $source $destin"
> rsync -av --progress --dry-run --log-file="$logfl" "$source" "$destin"
>
> elif (( filetr_exec == 1 )); then
>
> # use rsync archive option -a (equivalent to -rlptgoD)
> echo "rsync -av --progress --log-file=$logfl $source $destin"
> rsync -av --progress --log-file="$logfl" "$source" "$destin"
>
> else
>
> echo "rsync -av --progress --log-file=$logfl $source $destin"
Let's look at what's *different* in the two invocations. The only
difference between them is that one has --dry-run and the other does
not.
So, another approach would be to put the --dry-run option (or the absence
of it) into an array, instead of putting all of the common options into
an array.
dryrun=()
((filetr_dryrun)) && dryrun=(--dry-run)
if ((filetr_dryrun || filetr_exec)); then
rsync "${dryrun[@]}" -av --progress --log-file="$logfl" "$source" "$destin"
fi
I suspect you've misspelled "filter" a few times, but no big deal. More
confusing is how you're using the _exec option. I'm unclear on exactly
why you want the default case to be "echo the command as if I were going
to run it, but don't actually run it, not even with --dry-run", so I
suspect I'm missing some pieces of the goal.
It's something for you to think about.