aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Ankarstr\xf6m <john@ankarstrom.se>2021-06-03 09:28:28 +0200
committerJohn Ankarstr\xf6m <john@ankarstrom.se>2021-06-03 09:28:28 +0200
commit8b710c8969cf38b432fe81931fcce5ea8c8ba05c (patch)
tree1abc5fe0f7113d30ee5018502e7823381a268c26
parent75f6926390f33f62b95b355d48bc5454243ddcea (diff)
downloadxutil-8b710c8969cf38b432fe81931fcce5ea8c8ba05c.tar.gz
each: Support |, &&, || separators
-rwxr-xr-xeach12
-rw-r--r--each.116
2 files changed, 18 insertions, 10 deletions
diff --git a/each b/each
index bed5bb8..b1e5727 100755
--- a/each
+++ b/each
@@ -2,17 +2,17 @@
$i = 0;
for (@ARGV) {
- if (/^;$/) {
- $i++;
- next;
- }
+ if (/^;$/) { $command .= '; '; next; }
+ if (/^&&$/) { $command .= '&& '; next; }
+ if (/^\|\|$/) { $command .= '|| '; next; }
+ if (/^\|$/) { $command .= '| '; next; }
s/"/"'"'"/g;
s/\$/\\\$/g;
s/\\\$\+/\$/g;
- $commands[$i] .= "\"$_\" "
+ $command .= "\"$_\" "
}
while (<STDIN>) {
chomp($ENV{x} = $_);
- system($_) for @commands;
+ system($command);
}
diff --git a/each.1 b/each.1
index 9790be4..00780be 100644
--- a/each.1
+++ b/each.1
@@ -9,7 +9,7 @@
.Sh SYNOPSIS
.Nm each
.Ar command
-.Op Ar \\\\; command ...
+.Op Ar separator command ...
.
.Sh DESCIPTION
.Pp
@@ -17,7 +17,15 @@
runs each given
.Ar command
for every line read on standard input.
-With a command, the contents of the line is assigned to the variable
+.Ar separator
+is one of
+.Ql \&; ,
+.Ql | ,
+.Ql &&
+and
+.Ql || .
+.Pp
+Within a command, the contents of the line is assigned to the variable
.Ev x ,
which can be accessed with the normal shell variable interpolation syntax,
except you need to put a plus sign after the dollar sign:
@@ -30,9 +38,9 @@ $+{x%%.*}
.Ed
.Pp
This syntax generally doesn't need to be quoted
-when entered in the Bourne shell
+when entered in the Bourne or Korn shells
(unless you need to put commas inside the curly braces
-or have files who names begin with
+or have files whose names begin with
.Ql $+ ) .
.Sh AUTHORS
.Pp