[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: function with description
From: |
Chris F.A. Johnson |
Subject: |
Re: function with description |
Date: |
Mon, 28 Jun 2021 18:39:36 -0400 (EDT) |
User-agent: |
Alpine 2.22 (DEB 394 2020-01-19) |
On Tue, 29 Jun 2021, lisa-asket@perso.be wrote:
Have written the following function and would like to be able to print a
description
similar to the docstring in elisp.
Perhaps I can call the function this way `headrc h`
headrc ()
{
# Prints first set of lines from named files.
# $1 NUM Number of lines to print
# $2 DIR Directory
num=$1
dir=$2
find "$dir" \( -name \*.org -o -name \*.texi \) \
| xargs head -n "$num";
}
This is how I do it:
days_in_month() #@ Return number of days in given month
{ #@ USAGE: days_in_month MONTHNUM [year]
[ "$1" = -- ] && shift
case ${1#0} in
9|4|6|11) days_in_month=30 ;; ## 30 days hath September...
1|3|5|7|8|10|12) days_in_month=31 ;;
2) is_leap_year "$2" &&
days_in_month=29 ||
days_in_month=28
;;
*) return 5 ;;
esac
}
grep -A1 '()' file-of-functions
--
Chris F.A. Johnson <http://cfajohnson.com/>
=========================== Author: ===============================
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
Pro Bash Programming: Scripting the GNU/Linux shell (2009, Apress)