- $ variables usage, if condition bash loop over file on cyberciti
- if condition test in more detail test exiting value in bash from blog by sanctum
- $?, if condition test check exit status code from linuxcommando
python reference here
| #! /usr/bin/python | |
| import os | |
| import zipfile | |
| for root, dirs, files in os.walk('.'): | |
| for file in files: | |
| if file.endswith('.zip'): | |
| try: | |
| zfile = zipfile.ZipFile(file) | |
| except zipfile.BadZipfile as ex: | |
| print "%s no a zip file" % file | |
| continue | |
| ret = zfile.testzip() | |
| if ret is not None: | |
| print "%s bad zip file, error: %s" % file, ret | |
| else: | |
| print "%s OK" % file |
| #! /bin/bash | |
| for f in *.zip | |
| do | |
| zip --test $f 1>/dev/null && echo $f 'OK' | |
| if (($? > 0)); then | |
| # use double quote for $f to function | |
| printf '%s \n' "$f bad file" >&2 | |
| fi | |
| done |