allow line arguments
[tee-unique] / teeu
1 #!/bin/bash
2 # Copyright (C) 2014 Ian Kelling
3 # This program is under GPL v. 3 or later, see <http://www.gnu.org/licenses/>
4
5 teeu() {
6 local help="Usage: appendu [-h|--help] FILE [LINE]
7
8 Tee unique. Append each LINE or if none, each stdin line to FILE if it does not exist in FILE.
9
10 [-h|--help] display this message"
11
12
13 if [[ $1 == --help || $1 == -h ]]; then
14 echo "$help"
15 return
16 fi
17
18 if (( ${#@} == 0 )) ; then
19 echo "teeu error: need 1 or more arguments"
20 echo "$help"
21 return 1
22 fi
23 local file="$1"; shift
24
25 local MAPFILE
26 mapfile -t
27 for line in "${@:-$MAPFILE[@]}"; do
28 grep -xFq "$line" "$1" &>/dev/null || tee -a "$1" <<<"$line"
29 done
30 return 0
31 }
32 teeu "$@"