help-bash
[Top][All Lists]
Advanced

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

Using different options to run rsync


From: lisa-asket
Subject: Using different options to run rsync
Date: Mon, 19 Jul 2021 19:01:06 +0200 (CEST)

Have been cleaning things up and adding additional functionality.



oser=(-av --progress --log-file="$logfl")
(( filetr_dryrun == 1 )) && oser+=( --dry-run )
(( filetr_update == 1 )) && oser+=( --update )
(( filetr_backup == 1 )) && oser+=( --backup )


But although I have these options, the rsync transfer command is not supposed 
to run

until the user uses the --exec option available by the script



-e|--exec)
  local -r filetr_exec=1
  shift 1
  ;;



So unless the user sets `--exec`,  rsync should always use `--dry-run`.



I am struggling quite a bit setting `oser` so that `rsync` is executed when 
needed

according to the option passed.







From: Greg Wooledge <greg@wooledge.org>
To: help-bash@gnu.org
Subject: Re: Using different options to run rsync
Date: 19/07/2021 14:55:13 Europe/Paris

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.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]