Search code examples
bashwildcardrsyncquotingglob

Bash Wildcard and Variable Usage


What I'm trying to achieve is copying everything at source directory to destination directory by excluding the workspace directory, I have the following command to do so:

rsync -av --exclude='directory-name*/workspace' sourceDir destinationDir

which is working well, but if I try to use variable for the "directory-name":

VARIABLE_NAME="directory-name"
rsync -av --exclude='$VARIABLE_NAME*/workspace' sourceDir destinationDir

Solution

  • Variables are not expanded when put inside single quotes, use double quotes instead:

    rsync -av --exclude="$VARIABLE_NAME"'*/workspace' sourceDir destinationDir