Env variable in include file not expanded

I try the following:

cd /tmp
eval $(cat $HOME/.config/backup/backup-env.txt) \
restic backup --files-from  ~/.config/backup/backup-include.txt

The file backup-include.txt contains only


I get the error

/tmp/$HOME does not exist, skipping
Fatal: all target directories/files do not exist

This is not what I’m expecting. Why doesn’t expand restic the variable $HOME? Thanks in advance.


First, you can prevent issues with white spaces and quoting by directly sourcing the env file, like this (without $() and cat):

eval $HOME/.config/backup/backup-env.txt

I’d like to ask from the other side first: why should restic expand environment variables in the file passed to --files-from? If restic is started like restic backup $HOME, then the user’s shell will expand $HOME to /home/foo before passing the string to restic, so it’s not restic’s job to do that. We’d need to add special functionality to support this, so I’m interested in your reasoning.

Can you please describe your use case?

I understand. You are right. It’s not the job of restic to expand environment variables. I want to move the definitions of include/exclude to the files with using of environment variables, but this may be not a good idea. Sorry for the noise.