rewrite in bash language
rearrange arg logic