So I am a making a simple backup script, it will be run every hour. All this script does, is make a backup directory and copy files:
./backup/'$HOME'/Documents/todo.txt
backup structure
- backup
- '$HOME'
- Documents
- todo.txt
- Pictures
- etc
- ....
I keep the home variable in the name of the folder so it's not bound to one user.
Now, I am trying to make a restore script, which copies all the files in the backup folder, but my problem is, when I echo the structure, the $HOME
part is not parsed and echoed directly:
What it echos as:
/$HOME/Documents/todo.txt
What I want it to echo as
/home/myuser/Documents/todo.txt
The code I am using to loop over each file in the backup file and try and copy the file to the location:
for file in $(find backup -type f); do
echo "$file" | cut -c 7- | xargs -I {} cp $file {}
done
But, of course, this won't work, because the $HOME
folder in my backup
folder is not parsed to a variable. So is it possible to parse variable in a string to make them act like variables?