Pass space separated arguments stored in variable to command
As long as this is a bash script (or even most versions of sh) you should use an array to pass arguments rather than a variable:
DIRS=('/home/' '/var/www/html' '/etc')
tar -czf /backup/file.tar.gz "${DIRS[@]}"
This can be written as follows if you prefer (usually easier to read if the array gets large):
DIRS=(
'/home/'
'/var/www/html'
'/etc'
)
In a shell that does not support arrays you will need to unquote your variable to allow word splitting (Not recommended if it can be avoided):
DIRS="/home/ /var/www/html /etc"
tar -czf /backup/file.tar.gz ${DIRS}
When you quote the variable to pass these arguments it's essentially the same as:
tar -czf /backup/file.tar.gz "/home/ /var/www/html /etc"
However when you pass them through a quoted array it will be more like:
tar -czf /backup/file.tar.gz "/home/" "/var/www/html" "/etc"
Passing them through an unquoted array or variable will perform somthing similar to:
tar -czf /backup/file.tar.gz /home/ /var/www/html /etc
Which in this example should not be an issue but leaves it open to additional word splitting and other types of expansion that may be undesirable or potentially harmful.