The problem isn't tar, it's in your shell code. The argument of the
-C option is supposed to be a path, not a wildcard pattern. Notice that you had exactly the same problem with the
You stored a wildcard pattern in the
INSTALL_DIR variable. When you write
-C $INSTALL_DIR, this applies the “split+glob” operator: take the value of the variable, split it at whitespace, and interpret each word as a wildcard pattern which is then expanded. Here the value of the variable is
/Applications/Adobe Illustrator*/Cool Extras.localized/en_US/Templates, which is split into three words
Extras.localized/en_US/Templates; the middle word contains a wildcard (
*), so it's interpreted as a wildcard pattern, but since it doesn't match any file, the pattern is left as is. This makes the argument of the
-C option the string
/Applications/Adobe, and then there are two more arguments to the
If you use double quotes, then
"$INSTALL_DIR" is simply the value of the variable
INSTALL_DIR. With the
* still in it, since it was never expanded at any point.
As a rule of thumb, wildcards are expanded in contexts where multiple words are expected. After all, in general, wildcard patterns match multiple files. The right-hand side of an assignment suppresses wildcard expansion, because the result is expected to be a single string. To get a list instead, assign to an array variable instead of a string variable:
INSTALL_DIRS=(/Applications/Adobe\ Illustrator*/Cool\ Extras.localized/en_US/Templates)
There could potentially be multiple array elements, if you have multiple versions of Illustrator installed. Let's take the last element.
INSTALL_DIR is a path to an existing file (assuming that the wildcard did match). You can use it normally (i.e. you can expand it inside double quotes).
tar -xz "$SOURCE_ZIP" --strip-components 1 -C "$INSTALL_DIR" "*.ait"