#!/bin/bash
###### Some shell version or description here.###### Usage:### test <input> <output>###### Options:### <input> Input file to read.### <output> Output file to write. Use '-' for stdout.### -h | --help Show this message.
help(){
sed -rn 's/^### ?//;T;p'"$0"}# 如果用户输入“-h”或者无参数,执行help函数if[[$#==0]]||[["$1"=="-h"]]||[["$1"=="--help"]];thenhelpexit1fi
效果:
1
2
3
4
5
6
7
8
9
10
11
12
╭─agou-ops@ideapad-15ISK ~/tmp
╰─$ bash test.sh --help
Some shell version or description here.
Usage:
test <input> <output>
Options:
<input> Input file to read.
<output> Output file to write. Use '-'for stdout.
-h | --help Show this message.