Re: The "asort" extension (Was: feature proposal: expand associative arrays in lexicographic order ...)
Greg Wooledge <[email protected]>
| Newsgroups | gmane.comp.shells.bash.bugs |
|---|---|
| Message-ID | <[email protected]> |
On Wed, Aug 26, 2026 at 01:19:55 -0400, Zachary Santer wrote:
> This script is all about running commands and filtering their output
> through sed and awk. It makes sense as a bash script. If there's a
> more powerful programming language that can do the equivalent of
> ```
> shopt -s lastpipe
> command-1 |
> command-2 |
> while read whatever; do
> [...]
> done
> ```
> in some reasonable way, then count me in.
If most of the heavy lifting is being done by external programs, and
your script is just doing a little bit of post-processing, then bash is
actually a great choice of implementation language.
But since you requested it, here's one of the ways to achieve the same
end in Tcl:
hobbit:~$ cat foo
#!/usr/bin/env tclsh9.0
set pipe [open {| seq 10 | tac} r]
while {[gets $pipe line] >= 0} {
puts "Next line: $line"
}
close $pipe
hobbit:~$ ./foo
Next line: 10
Next line: 9
Next line: 8
Next line: 7
Next line: 6
Next line: 5
Next line: 4
Next line: 3
Next line: 2
Next line: 1
There are some limitations on the commands that can be executed this way
(e.g. a simple command where one of the arguments begins with the |
character cannot be run this way), and I'm not up to date on the latest
discussions of this issue in Tcl. But with most static commands, it
should be OK.