Anubhav<p><a href="https://hachyderm.io/tags/PSA" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>PSA</span></a>: People, do not give empty strings to <a href="https://hachyderm.io/tags/rsync" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>rsync</span></a> v3.1.3 for it to include current directory as additional source directory to be copied over.</p><p>test=''<br>delete=''</p><p># Later, set test='-n' & delete='--delete' on some conditions.</p><p>...</p><p>rsync -n -v -v -r -i \<br>"$test" "$delete" \<br>"${source_dir:?Missing source}" \<br>"${dest_dir:?Missing dest}"<br>sending incremental file list<br>removing duplicate name . from file list (2)<br>removing duplicate name . from file list (3)<br>...</p><p>Without the second -v option there would be no indication of inclusion of current directory.</p><p>That happens at least in rsync v3.1.3 protocol version 31 (Rocky Linux 8) but not in v{3.2.7,3.4.1} protocol version 32 (Debian 12,FreeBSD 14.3) where it exits with error thankfully:</p><p>Empty source arg specified.<br>rsync error: syntax or usage error (code 1) at main.c(1508) [sender=3.2.7]</p><p>This (with rsync v3.1.x above) came about due to:<br>1- unconditional inclusion of empty strings;<br>2- use of Bash array syntax to provide options to rsync. It was changed to `rsync "${rsync_opt[@]}" ...` from earlier change of `set -- $rsync_opt; rsync $@ ...` which collapses empty strings. See the script below.</p><p>#!/usr/bin/env bash</p><p>conditional_string=''</p><p>more_arg='-v -r'</p><p># Later.<br>collected_array=("${more_arg}" "${conditional_string}")<br>collected_plain_string="${more_arg} ${conditional_string}"</p><p>printf "array: >%s<\n" "${collected_array[@]}"<br>printf "array as string: >%s<\n" "${collected_array}"</p><p>set -- "${collected_array[@]}"<br>printf "@, from quoted array: >%s<\n" "$@"</p><p>set -- $collected_array<br>printf "@, from unadorned unquoted array: >%s<\n" "$@"</p><p>printf "\n-----\n"</p><p>printf "plain string: >%s<\n" "${collected_plain_string}"<br>set -- $collected_plain_string<br>printf "@, from unquoted plain string: >%s<\n" "$@"</p><p>Script Output:<br>array: >-v -r<<br>array: ><<br>array as string: >-v -r<<br>@, from quoted array: >-v -r<<br>@, from quoted array: ><<br>@, from unadorned unquoted array: >-v<<br>@, from unadorned unquoted array: >-r<</p><p>-----<br>plain string: >-v -r <<br>@, from unquoted plain string: >-v<<br>@, from unquoted plain string: >-r<</p><p><a href="https://hachyderm.io/tags/shellScript" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>shellScript</span></a> <a href="https://hachyderm.io/tags/bash" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>bash</span></a> <a href="https://hachyderm.io/tags/softwareDevelopment" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>softwareDevelopment</span></a></p>