allow line arguments
authorIan Kelling <ian@iankelling.org>
Mon, 11 Aug 2014 17:11:37 +0000 (10:11 -0700)
committerIan Kelling <ian@iankelling.org>
Mon, 11 Aug 2014 17:11:37 +0000 (10:11 -0700)
teeu
teeu-function

diff --git a/teeu b/teeu
index 44718f94ed6b696c9ee1f706050bff720cabb144..5be4b7688b3d14310a79efb5749e643cc3704027 100755 (executable)
--- a/teeu
+++ b/teeu
@@ -3,9 +3,9 @@
 # This program is under GPL v. 3 or later, see <http://www.gnu.org/licenses/>
 
 teeu() {
 # This program is under GPL v. 3 or later, see <http://www.gnu.org/licenses/>
 
 teeu() {
-    local help="Usage: appendu [-h|--help] FILE
+    local help="Usage: appendu [-h|--help] FILE [LINE]
 
 
-Tee unique. Append each stdin line if it does not exist in the file.
+Tee unique. Append each LINE or if none, each stdin line to FILE if it does not exist in FILE.
 
   [-h|--help]  display this message"
 
 
   [-h|--help]  display this message"
 
@@ -15,15 +15,16 @@ Tee unique. Append each stdin line if it does not exist in the file.
         return
     fi
     
         return
     fi
     
-    if [[ ${#@} == 0 ]]; then
-        echo "error: need 1 or more arguments"
+    if (( ${#@} == 0 )) ; then
+        echo "teeu error: need 1 or more arguments"
         echo "$help"
         return 1
     fi
         echo "$help"
         return 1
     fi
+    local file="$1"; shift
 
     local MAPFILE
     mapfile -t
 
     local MAPFILE
     mapfile -t
-    for line in "${MAPFILE[@]}"; do
+    for line in "${@:-$MAPFILE[@]}"; do
         grep -xFq "$line" "$1" &>/dev/null || tee -a "$1" <<<"$line"
     done
     return 0
         grep -xFq "$line" "$1" &>/dev/null || tee -a "$1" <<<"$line"
     done
     return 0
index cc55ff15d1c0500b5834178c9908a893da98a1a7..5845aff2c40cdfe88597fc762b8932ff2b2ef20a 100644 (file)
@@ -3,9 +3,9 @@
 # This program is under GPL v. 3 or later, see <http://www.gnu.org/licenses/>
 
 teeu() {
 # This program is under GPL v. 3 or later, see <http://www.gnu.org/licenses/>
 
 teeu() {
-    local help="Usage: appendu [-h|--help] FILE
+    local help="Usage: appendu [-h|--help] FILE [LINE]
 
 
-Tee unique. Append each stdin line if it does not exist in the file.
+Tee unique. Append each LINE or if none, each stdin line to FILE if it does not exist in FILE.
 
   [-h|--help]  display this message"
 
 
   [-h|--help]  display this message"
 
@@ -15,15 +15,16 @@ Tee unique. Append each stdin line if it does not exist in the file.
         return
     fi
     
         return
     fi
     
-    if [[ ${#@} == 0 ]]; then
-        echo "error: need 1 or more arguments"
+    if (( ${#@} == 0 )) ; then
+        echo "teeu error: need 1 or more arguments"
         echo "$help"
         return 1
     fi
         echo "$help"
         return 1
     fi
+    local file="$1"; shift
 
     local MAPFILE
     mapfile -t
 
     local MAPFILE
     mapfile -t
-    for line in "${MAPFILE[@]}"; do
+    for line in "${@:-$MAPFILE[@]}"; do
         grep -xFq "$line" "$1" &>/dev/null || tee -a "$1" <<<"$line"
     done
     return 0
         grep -xFq "$line" "$1" &>/dev/null || tee -a "$1" <<<"$line"
     done
     return 0