内容简介:Have you ever thought how good it would be to have a help message for your shell script that you wrote a month ago and already forgot what it is supposed to do?Yeah, there is always a way to show a message using cat (meow) or a bunch of echo calls.But ther
Have you ever thought how good it would be to have a help message for your shell script that you wrote a month ago and already forgot what it is supposed to do?
Yeah, there is always a way to show a message using cat (meow) or a bunch of echo calls.
But there is a neat trick.
Add your message with all the required information on top of your file, just right after the shebang.
#!/bin/bash ### ### my-script — does one thing well ### ### Usage: ### my-script <input> <output> ### ### Options: ### <input> Input file to read. ### <output> Output file to write. Use '-' for stdout. ### -h Show this message.
Halfway done, now need to get this message in runtime with sed.
help() {
sed -rn 's/^### ?//;T;p' "$0"
}
$0
means a filename of a file that is being executed.
A bit about the magic that is going here:
s / ^### ? // T p
Now just call the help
function if an arg -h
or no args passed.
if [[ $# == 0 ]] || [[ "$1" == "-h" ]]; then
help
exit 1
fi
Hope it helps, cheers!
Full gist is available on GitHub: https://gist.github.com/kovetskiy/a4bb510595b3a6b17bfd1bd9ac8bb4a5
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
猜你喜欢:本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
蚁群算法及其应用
李士勇 / 哈工大出版社 / 2004-9 / 25.00元
蚁群算法是意大利学者Dorigo等人于1991年创立的,是继神经网络、遗传算法、免疫算法之后的又一种新兴的启发式搜索算法。蚂蚁群体是一种社会性昆虫,它们有组织、有分工,还有通讯系统,它们相互协作,能完成从蚁穴到食物源寻找最短路径的复杂任务。模拟蚂蚁群体智能的人工蚁群算法具有分布计算、信息正反馈和启发式搜索的特点,不仅在求解组合优化问题中获得广泛应用,而且也用于连续时间系统的优化。 《蚁群算......一起来看看 《蚁群算法及其应用》 这本书的介绍吧!