I built a simple generic wrapper script to simplify some of the most needed restic functionality.
E.g. passing an exclude list as environment variable:
export EXCLUDES="--exclude=~/restic/sources/excluded --exclude=~/sources/excluded2"
, which is then included in inside this wrapper (simplified case):
restic backup $EXCLUDES ~/restic/sources
This works, but I still have a problem for file paths with spaces.
For a subfolder
~/sources/excluded 3, both of the following won’t parse properly:
export EXCLUDES="--exclude=\"/home/user/restic/sources/excluded 3\"" # (1) export EXCLUDES="--exclude='/home/user/restic/sources/excluded 3'" # (2)
set -x, the relevant part of restic command is logged like this:
'--exclude="/home/user/restic/sources/excluded' '3"' # (1) '--exclude='\''/home/user/restic/sources/excluded' '3'\''' # (2)
, whose quotes I don’t really understand.
I also came across bash - Why does my shell script choke on whitespace or other special characters? - Unix & Linux Stack Exchange, but still cannot grasp above shell rules for quotes.
How might I change
EXCLUDES, so an argument with spaces is interpreted correctly?
For sure there is
--exclude-file, but I am mostly interested, how the shell works here.