i have a bash/shell script and want to store a command output in a variable (EXCLUDE_PATTERN) and the command itself contains also variables (FOLDERS and BUPATH).
the goal with this command is to replace the spaces in the variable FOLDERS with " --exclude="$BUPATH for use in an tar command
if have defined the following variables in the script:
FOLDERS='folder1 folder2 folder3'
BUPATH='/opt/mypath'
CONFIG_BACKUP="/storage/backup.tar.gz"
FOLDER is a variable with a list of excluded folders
BUPATH is a variable with a path
Now i want to define a variable EXCLUDE_PATTERN with the pattern for a following tar command (tried 2 variations):
EXCLUDE_PATTERN=`echo $FOLDERS | sed 's/\ /" --exclude="$BUPATH\//g'`
EXCLUDE_PATTERN=`echo $FOLDERS | sed 's/\ /" --exclude="${BUPATH}\//g'`
Then the script runs the tar command:
tar -C \"$BUPATH\" --exclude=\"$BUPATH/$EXCLUDE_PATTERN\" -czf \"$CONFIG_BACKUP\" .
It seems that the variable EXCLUDE_PATTERN is not recognizing the BUPATH variable:
tar -C "/opt/mypath" --exclude="/opt/mypath/folder1" --exclude="${BUPATH}/folder2" --exclude="${BUPATH}/folder3" -czf "/storage/config.tar.gz" .
The expected command should be this:
tar -C "/opt/mypath" --exclude="/opt/mypath/folder1" --exclude="/opt/mypath/folder2" --exclude="/opt/mypath/folder3" -czf "/storage/config.tar.gz" .
I hope someone can help me with this :)