fix regression
[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 if [[ $1 == --help || $1 == -h ]]; then
13 echo "$help"
14 return
15 fi
16
17 if (( ${#@} == 0 )) ; then
18 echo "teeu error: need 1 or more arguments"
19 echo "$help"
20 return 1
21 fi
22 local MAPFILE
23 (( ${#@} >= 2 )) && MAPFILE="${@:2}" || mapfile -t
24 for line in "${MAPFILE[@]}"; do
25 grep -xFq "$line" "$1" &>/dev/null || tee -a "$1" <<<"$line"
26 done
27 return 0
28 }
29 teeu "$@"