Artificial intelligent assistant

Adding options using bash arrays I am using a bash script to call `rsync` commands. Have decided to collect some options in an array called `oser`. The idea is to look at what's different in the two invocations and put that into the array, instead of putting all of the common options into the array. Now I would like to add the --backup possibility to `rsync` and getting confused on how to go about with the implementation oser=() (( filetr_dryrun == 1 )) && oser=(--dry-run) if (( filetr_dryrun == 1 )); then rsync "${oser[@]}" -av --progress --log-file="$logfl" "$source" "$destin" elif (( filetr_exec == 1 )); then rsync "${oser[@]}" -av --progress --log-file="$logfl" "$source" "$destin" else rsync "${oser[@]}" -av --progress --log-file="$logfl" "$source" "$destin" fi

How about this:


# "always" options: you can put any whitespace in the array definition
oser=(
-av
--progress
--log-file="$logfl"
)

# note the `+=` below to _append_ to the array
(( filetr_dryrun == 1 )) && oser+=( --dry-run )

# now, `oser` contains all the options
rsync "${oser[@]}" "$source" "$destin"


Now, if you want to add more options, just add them into the initial `oser=(...)` definition, or if there's some condition, use `oser+=(...)` to append to the array.

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 26e9ff90cec956f098fa2571ddd35752