This is a good script template which returns JSON response, it has exit hook, logs and arguments checking. I will continuously update it if I find good patterns.
Use Python
script is more developer friendly and easy to maintain.
对于一般用途的script,有几点需要注意:
- shebang 必须有
#!/usr/bin/env bash
or#!/usr/bin/env sh
- debug
set
放开头, 如同这里一样 - usage 函数格式要清晰,可以参考这个例子,且必须有
-h/--help
flag - 传入的argument 要检查个数,以及是否为空
- 参数输入多多测试不同情况
- 可能需要log,可用temp 以及 exit hook解决,log放
/tmp
directory - 输出信息用[date time] prefix, 可以用LogMsg function wrap一下
Using #
for comment is preferred, but you can comment multi-line by heredoc:
1 | : <<'END_COMMENT' |
1 |
|