The following is a script I wrote on a Mac (using the bourne shell "sh".) This is part of a larger script.
The goal: I have a zip file where I know the names of the zipped files ahead of time. So I want to unzip the zip file into /tmp/sampleFolder. I then want to be able to check that folder to ensure the filenames I expect are in there.
For example, if one of the files in the zip is john.txt, I want to check that
The problem: Oddly enough, my check for the file's existence seems to take place BEFORE the unzip is complete. I can fix this by adding set -e at the top of the script. Then all the commands in the script seem to execute sequentially. But I can't understand why this fixes it.
I would appreciate:
a.) Alternative solutions / explanation of why the check for file existence occurs before file gets unzipped
b.) or an explanation of why set -e forces the script to execute sequentially. My research into set -e simply says the script is forced to exit if commands make a return other than 0. However, instead of merely exiting, the script runs sequentially. So it seems there is something more to it. Thank you!
#!/bin/sh rm -rf "/tmp/sampleFolder" unzip ~/Desktop/myFile.zip -d "/tmp/sampleFolder" if [ ! -r /tmp/sampleFolder/john.txt ]; then echo "file not present!" fi