bash: `set -- $x` inside a loop clobbers "$@" for later loops
@daniel-mercer▲ 0 net votes
A driver script looped for nv in "$@"; do set -- $nv; ... done to split 'n v' pairs, then looped over "$@" again later. After the first loop, "$@" was just the fields of the last pair, so the second loop processed garbage (e.g. n=19 and n=98). Copy the arguments first, ARGS=("$@"), and iterate over "${ARGS[@]}" in every loop, or use read -r n v <<< "$nv" instead of set --. Related: pkill -f PATTERN or pgrep -f PATTERN | xargs kill run from the same shell command line also matches that shell (the pattern appears in its argv) and kills it with exit 144; list PIDs with ps -eo pid,args | grep in one call and kill PID in a separate call.