Is "special characters must be escaped" always true?

Hello:
Perhaps I am being too rigid or have not completely understood the documentation. The file names in the --exclude or --files-from are described in the documentation as when they have special characters the “special characters must be escaped”. But is this actually true?
I am running restic 0.9.6 on an up to date Windows 10. I have been doing some minor testing and put the following in a excludes.txt:
K:\test\restic\file with $ in middle of name.txt
The $ was not escaped but the file was excluded from the backup. So I am asking if the $ needs to be escaped only when there is a matching environment variable name after the “$”?
Here is the corner case that I’m thinking about: The documentation says:

Blockquote
For example maybe you want to backup files which have a name that matches a certain pattern:
$ find /tmp/somefiles | grep ‘PATTERN’ > /tmp/files_to_backup
You can then use restic to backup the filtered files:
$ restic -r /srv/restic-repo backup --files-from /tmp/files_to_backup
Blockquote
But does that actually work if the user has any special characters in the names of the files? The files-from is a plain file list and any special characters are not escaped. If someone had a file with the “$USER” (that is the characters: dollarsign USER) as part of the name would it actually be backed up by the above documentation commands?

Also, is there documentation on what happens if a file or directory matches both the files-from and the excludes?
Sorry to be a bit of a pain in the rear end but I do like restic and was having problems excluding $RECYCLE.BIN and went off on a bit of a tangent.
Is there a way to donate money?

You do need to escape $ when it is used in a syntactically-valid environment variable name, regardless of whether or not it is set.

In the first case, $ is not followed by alphanumeric characters (it is followed by a space) and this is not a valid environment variable name – a variable must have at least one character in its name. Therefore, the $ is taken literally.

In the second case, $RECYCLE is a valid environment variable name even though it has no value. Therefore, $RECYCLE.BIN becomes .BIN when the empty value is substituted.

Consider instead:

find /tmp/somefiles | grep 'PATTERN' | sed 's/\$/$$/g' > /tmp/files_to_backup
2 Likes

Thank you sir. This is exactly what I needed to know. I hope this will be added to the documentation. Not being able to exclude the $RECYCLE.BIN may be one of the causes of variability in running time of a backup.

2 Likes