简体   繁体   中英

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 

您是否尝试过用反斜杠转义星号:

excludes='"dir1/\*"'

This should work:

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

Or even this should work:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM