summaryrefslogtreecommitdiff
path: root/shquote.sh
blob: bd53abb14390bfae1d7a76cf89744ae2ea7aa67e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/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