From 3df80b5afbebbf3af63b49fe98a3faecd2b68439 Mon Sep 17 00:00:00 2001 From: Jan T Date: Thu, 13 Nov 2025 11:31:30 +0000 Subject: Initial commit --- tools/each | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100755 tools/each (limited to 'tools/each') diff --git a/tools/each b/tools/each new file mode 100755 index 0000000..da5ce84 --- /dev/null +++ b/tools/each @@ -0,0 +1,21 @@ +#!/bin/sh + +if [ -z "$1" ]; then + echo "Usage: $0 " + echo "" + echo "Run the given command for each newline-separated line in stdin (think for-each in many programming languages)." + echo 'The iterator variable is called "$ELEM", and the index variable is called "$IDX".' + exit 1 +fi + +i=0 +while IFS=$'\n' read -r line; do + j=0 + for item in $line; do + eval "X${j}='$item'" + j=$((j+1)) + done + + IDX=$i ELEM="$line" eval "$1" + i=$((i+1)) +done -- cgit v1.3