有个十几G的目录,需要压缩成Zip,准备写个脚本,Python和shell均可,那,怎么知道压缩成功还是失败了?
在shell中,使用$?
判断,如果该值为0,则说明上个命令执行成功。
Shell
#!/usr/bin/env bash zip -r target.zip target_dir/ if [ $? -eq 0 ]; then echo "Success" else echo "Failed" fi
Python
#!/usr/bin/env python import commands status = commands.getstatusoutput("zip -r target.zip target_dir/")[0] if status == 0: print "Success" else: print "Failed"