user3388884
user3388884

Reputation: 5098

Linux command variable substitution

I would like to zip all files/dirs while excluding a few listed within the variable $excludes. However the following piece of code is not excluding those files.

excludes='"dir1/*" "dir2/*" "dir3/*"'
zip -r zipfile * -x $excludes 

Upvotes: 2

Views: 86

Answers (2)

anubhava
anubhava

Reputation: 786091

This should work:

zip -r zipfile * -x dir1/* dir2/* dir3/*

Or even this should work:

excludes='dir1/* dir2/* dir3/*'
zip -r zipfile * -x "$excludes"

Upvotes: 1

Snake
Snake

Reputation: 805

Have you tried escaping the asterisk with a backslash:

excludes='"dir1/\*"'

Upvotes: 1

Related Questions