In this and other cases, you can just use "if sg_persist_do_cmd ...; then ..." directly, no need for the $? + if clause.