Hi there,
I am building an backup script and have a problem. After building an exclude information part for the find command and using it inside the command it is going to be escaping me my ' all the time. At the moment I could fix it using eval - but I would love to not use it. So my question is:
How can I use a variable containing single quotes and paths inside another command as variable?
Code part:
Code
- LOCALBACKUP="/home/ /root/ /var/www/virtual/ /etc/ /var/mail/ /var/www/imscp/ /var/log/ /var/mail/"
- EXCLUDEPATHS="/home/ark/* /var/www/virtual/*/backups/* /var/log/mysql/*"
- TAREXCLUDE=""
- IFS=' '
- read -ra EXCL <<< "$EXCLUDEPATHS"
- for i in "${EXCL[@]}"; do
- TAREXCLUDE="${TAREXCLUDE} -not -path '${i}'"
- done
- # show command outputs
- set -x
- eval "find $LOCALBACKUP -type f $TAREXCLUDE -print > /opt/backups_$backupName/backup_files.lst"
In this command I build for each EXCLUDEPATHS this entry: -not -path '/home/ark/*'
But this part is escaped in the command: -not -path '\''/home/ark/*'\''
All in all I just need help with the last command ...
Can someone help me please?