Archived
1
0
Fork 0
This repository has been archived on 2025-03-10. You can view files and clone it, but cannot push or open issues or pull requests.
shbot/shquote.sh
Julien Dessaux 1e2d74064e Merge pull request #2 from vivia/master
Added timestamp to author on quotes module.
2013-11-10 09:58:07 +01:00

26 lines
689 B
Bash

#!/bin/bash
if [ -n "$2" ]; then
ARGS=$* && ARGS=($ARGS)
OWNER=$1
LEN=`expr ${#ARGS[*]}`
QUOTE=${ARGS[@]:1:$LEN}
TIMESTAMP=`date +"%Y-%m-%d %H:%M UTC %z"`
echo "${OWNER} ${TIMESTAMP}" >> shquote.txt
echo "${QUOTE}" >> shquote.txt
#elif [ -n "$1" ]; then
# TODO : quote someone
else
NB_LINES=(`wc -l shquote.txt`)
LINE=$((RANDOM * NB_LINES[0] / 65534))
# IFS="\r" LINES=(`tail -n $((LINE + 2)) shquote.txt | head -n 2`)
# QUOTE=${LINES[0]}
# OWNER=${LINES[1]}
QUOTE=`tail -n $((LINE * 2 + 1)) shquote.txt | head -n 1`
OWNER=`tail -n $((LINE * 2 + 2)) shquote.txt | head -n 1`
echo "\"${QUOTE}\""
echo "-- ${OWNER}"
fi