check if directory exists with '-d' instead of '-f'
changed mailx to $MAILX_BIN in final command