projects
/
BK-2020-03.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
chore(unitproc/bkt-processArgs):Update with die()
[BK-2020-03.git]
/
unitproc
/
bkshuf
diff --git
a/unitproc/bkshuf
b/unitproc/bkshuf
old mode 100644
(file)
new mode 100755
(executable)
index
8aaac9d
..
ff80d8e
--- a/
unitproc/bkshuf
+++ b/
unitproc/bkshuf
@@
-1,10
+1,12
@@
#!/usr/bin/env bash
# Desc: Mixes input lines while also preserving some neighbors
# Usage: cat file | bkshuf arg1
#!/usr/bin/env bash
# Desc: Mixes input lines while also preserving some neighbors
# Usage: cat file | bkshuf arg1
-# Version 0.
1
.0
+# Version 0.
2
.0
# Depends: bc 1.07.1, GNU Coreutils 8.32 (shuf)
# Input: var: arg1 initial lines to output
# Depends: bc 1.07.1, GNU Coreutils 8.32 (shuf)
# Input: var: arg1 initial lines to output
+trap 'exit;' SIGPIPE; # exit early if stdout not being read
+
# Load env vars
## For these numbers of lines of input...
if [[ ! -v BKSHUF_PARAM_LINEC ]]; then BKSHUF_PARAM_LINEC=1000000; fi;
# Load env vars
## For these numbers of lines of input...
if [[ ! -v BKSHUF_PARAM_LINEC ]]; then BKSHUF_PARAM_LINEC=1000000; fi;
@@
-88,7
+90,8
@@
consume_line() {
line="${list_input[$ip]}";
if [[ -n $line ]]; then
##### consume line at index ip
line="${list_input[$ip]}";
if [[ -n $line ]]; then
##### consume line at index ip
- printf "%s\n" "$line" & # print to output
+ printf "%s\n" "$line"; # print to output
+
unset "list_input[$ip]"; # destroy line in list_input array
((lc_out++));
((lcr--)); # decrement line count remaining lcr
unset "list_input[$ip]"; # destroy line in list_input array
((lc_out++));
((lcr--)); # decrement line count remaining lcr
@@
-124,7
+127,12
@@
main() {
else
lc_out_max="$1"; # output line count
fi;
else
lc_out_max="$1"; # output line count
fi;
-
+
+ # Check env vars
+ if ! checkInt "$BKSHUF_PARAM_LINEC"; then
+ die "FATAL:Not an int:BKSHUF_PARAM_LINEC:$BKSHUF_PARAM_LINEC"; fi;
+ if ! checkInt "$BKSHUF_PARAM_GSIZE"; then
+ die "FATAL:Not an int:BKSHUF_PARAM_LINEC:$BKSHUF_PARAM_GSIZE"; fi;
# store input lines from stdin (like `shuf`)
while read -r line; do
# store input lines from stdin (like `shuf`)
while read -r line; do
@@
-156,6
+164,7
@@
main() {
lc_out="0"; # init output line counter
if [[ -z "$lc_out_max" ]]; then lc_out_max="$lco"; fi;
ip="$(shuf -i0-$(( lco - 1 )) -n1)"; # init input index pointer
lc_out="0"; # init output line counter
if [[ -z "$lc_out_max" ]]; then lc_out_max="$lco"; fi;
ip="$(shuf -i0-$(( lco - 1 )) -n1)"; # init input index pointer
+ RANDOM="$(shuf -i0-32767 -n1)"; # init Bash PRNG
n_loop1="0";
#yell "DEBUG:max_blanks:$max_blanks"
while [[ $lcr -ge 1 ]] && [[ $lc_out -lt $lc_out_max ]]; do
n_loop1="0";
#yell "DEBUG:max_blanks:$max_blanks"
while [[ $lcr -ge 1 ]] && [[ $lc_out -lt $lc_out_max ]]; do