Created
May 31, 2014 01:18
-
-
Save babarot/7c597c08afd52e353e1c to your computer and use it in GitHub Desktop.
Count the number of command made in sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
FILE=~/.bash_myhistory | |
if [ "$1" = "-h" ]; then | |
echo 1>&2 "usage: noc [-h|-l] [<num>]" | |
echo 1>&2 " -h display this help and exit" | |
echo 1>&2 " -l display most recently used list" | |
echo 1>&2 " (range: 0~<num>: default num zero)" | |
exit 1 | |
fi | |
if [ "$1" = "-l" ]; then | |
for i in `seq 0 "${2:-9}"` | |
do | |
printf "%d\t%s\t%5d\n" $i $(date -v-${i}d '+%Y-%m-%d') $(grep -c `date -v-${i}d '+%Y-%m-%d'` $FILE) | |
done | |
exit 0 | |
fi | |
grep -c `date -v-${1:-0}d '+%Y-%m-%d'` $FILE | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment