0

I have a tar command to create .tar.gz file. It looks like below:

exclude="--exclude='.cache' --exclude='.composer' --exclude='.local' --exclude='.config'"

tar "$exclude" -czf "$backupsDir/$timestamp-home.tar.gz" /home

The problem is the $exclude variable in not evaluated and excluded directories are still in the archive. Can somebody tell me what is wrong with it? Thanks a lot.

Čamo
  • 3,863
  • 13
  • 62
  • 114
  • 2
    See [BashFAQ #50](https://mywiki.wooledge.org/BashFAQ/050). Argument lists should be stored in arrays, not strings. – Charles Duffy Mar 30 '21 at 11:32
  • 1
    See: [Variable containing multiple args with quotes in Bash](https://stackoverflow.com/q/7454526/7939871) – Léa Gris Mar 30 '21 at 11:39
  • @CharlesDuffy I think the one I mentioned is a better duplicate parent to link this to. https://stackoverflow.com/q/7454526/7939871 – Léa Gris Mar 30 '21 at 11:41
  • @LéaGris, I've updated the list of duplicates, though I'm wary of the level of pro-`eval` sentiment in the answers to the new addition; folks who don't understand the risks are liable to end up in trouble. – Charles Duffy Mar 30 '21 at 12:17
  • 1
    Thanks it works. In my opinion the @CharlesDuffy's answer is cleaner and easier to understand. – Čamo Mar 30 '21 at 12:19

0 Answers0