I'm trying to test if an archive has all its files. All I need to do is a simple unzip and then make. The shell keeps trying to interpret arguments like -aoq
as a program. Other errors exist as well, but I'll spare readers each and every way not to do it. Here are some of the failed attempts:
Failed:
RESULT=$(unzip -aoq cryptopp563.zip -d "$TMP/cryptopp563-zip/")
if [[ "$RESULT" -eq "0" ]]; then ... fi;
RESULT=$(unzip (-aoq cryptopp563.zip -d "$TMP/cryptopp563-zip/"))
if [[ "$RESULT" -eq "0" ]]; then ... fi;
RESULT=$(unzip ("-aoq" "cryptopp.zip" "-d" "$TMP/cryptopp-zip/"))
if [[ "$RESULT" -eq "0" ]]; then ... fi;
RESULT=$(unzip "-aoq cryptopp563.zip -d $TMP/cryptopp563-zip/")
if [[ "$RESULT" -eq "0" ]]; then ... fi;
RESULT=$(unzip "{-aoq cryptopp563.zip -d "$TMP/cryptopp563-zip/"}")
if [[ "$RESULT" -eq "0" ]]; then ... fi;
RESULT=$(unzip "(-aoq cryptopp563.zip -d "$TMP/cryptopp563-zip/")")
if [[ "$RESULT" -eq "0" ]]; then
...
If I see one more question and answer that says "just use parenthesis", "just use quotes" or "just use curly braces" I think I am going to scream...
How do I call unzip
with arguments so that Bash does not try to interpret the arguments as commands?
Here's a couple of the more comical error messages:
unzip: cannot find or open {-aoq cryptopp563.zip -d /tmp/cryptopp563-zip/}, {-aoq cryptopp563.zip -d
/tmp/cryptopp563-zip/}.zip or {-aoq cryptopp563.zip -d /tmp/cryptopp563-zip/}.ZIP.
unzip: cannot find or open (-aoq cryptopp563.zip -d /tmp/cryptopp563-zip/), (-aoq cryptopp563.zip -d
/tmp/cryptopp563-zip/).zip or (-aoq cryptopp563.zip -d /tmp/cryptopp563-zip/).ZIP.
Here are a few questions/answers that did not work for me. I'm fairly certain I have visited U&L.SE, Stack Overflow and Super User multiple times.
unzip
really going to be0
, or did you mean to instead inspect$?
for the exit code ofunzip
? – thrig Sep 9 '16 at 18:09if [[ ( $(unzip ...) -eq "0") ]]; then ... fi
. But I broke it out into two parts when trying to make it work. – jww Sep 9 '16 at 18:12RESULT=$(unzip -aoq cryptopp563.zip -d "$TMP/cryptopp563-zip/")
) and it works perfectly. Of course they're is nothing in$RESULT
since the command does no output but it does extract the files to the expected location. – Julie Pelletier Sep 9 '16 at 18:21