d3c1f027e76b68259a107b442e73b8c8e4d280eb
3 # Desc: Template function to write data supplied as argument
5 yell
() { echo "$0: $*" >&2; } # Yell, Die, Try Three-Fingered Claw technique; # Ref/Attrib: https://stackoverflow.com/a/25515370
6 die
() { yell
"$*"; exit 111; }
7 try
() { "$@" || die
"cannot $*"; }
9 # Desc: Writes first argument with subsequent arguments as options
10 # Usage: writeArg "$(echo "Data to be written.")" [output path] ([cmd1] [cmd2] [cmd3] [cmd4]...)
11 # Input: arg1: data to be written
13 # arg3+: command strings (ex: "gpsbabel -i nmea -f - -o kml -F - ")
14 # Output: file written to disk
15 # Example: decrypt multiple large files in parallel
16 # writeArg "$(cat /tmp/largefile1.gpg)" /tmp/largefile1 "gpg --decrypt" &
17 # writeArg "$(cat /tmp/largefile2.gpg)" /tmp/largefile2 "gpg --decrypt" &
18 # writeArg "$(cat /tmp/largefile3.gpg)" /tmp/largefile3 "gpg --decrypt" &
22 if ! [ -z "$3" ]; then CMD1
="$3"; else CMD1
="tee /dev/null "; fi # command string 1
23 if ! [ -z "$4" ]; then CMD2
="$4"; else CMD2
="tee /dev/null "; fi # command string 2
24 if ! [ -z "$5" ]; then CMD3
="$5"; else CMD3
="tee /dev/null "; fi # command string 3
25 if ! [ -z "$6" ]; then CMD4
="$6"; else CMD4
="tee /dev/null "; fi # command string 4
33 echo "$1" |
$CMD1 |
$CMD2 |
$CMD3 |
$CMD4 > "$2";
35 } # Write Bash var to file
37 #==BEGIN sample code==
38 myFile
="/tmp/$(date +%s)..original"
39 echo "how are you doing?" > "$myFile"
40 myVAR
="$(cat $myFile)"
41 writeArg
"$myVAR" "$myFile..LOUD_CHILD" "tee /tmp/cloneityclone " "tr '[:lower:]' '[:upper:]'"
44 # Author: Steven Baltakatei Sandoval