Some good templates for writing codes (shell, python, etc) were provided in this post.

Shell script

  1. Specify shebang in the beginning of shell script, which tells the loader which interpreter should be called, this helps as different bashes have different syntaxes. In the following case, shebang line tells the loader to use user-preferred bash.
  2. Add error handling: set -o errexit;, this will abort the execution of current shell script, if any command fails to be executed. When something wrong happens, this strategy helps you to locate the problem quickly, as traceback information will be highlighted at the line that the error actually occurs.
1
2
#!/usr/bin/env bash
set -o errexit;

Python script

  1. Specify shebang in the beginning of python scripts, if you want to run the script directly ./one_script.py.
  2. Define Python source code encodings so that non-Latin characters will not disrupt the execution of a script.
1
2
#!/usr/bin/env python
# coding=utf-8