Re: I think bash logic in a loop like : while [ condition] |read somevar
From:
Greg Wooledge
Subject:
Re: I think bash logic in a loop like : while [ condition] |read somevar is flawed.
Date:
Tue, 24 Dec 2013 13:56:32 -0500
User-agent:
Mutt/1.4.2.3i
On Tue, Dec 24, 2013 at 07:49:28PM +0100, rens wrote:
> I understand the technical origin of the behaviour.
> Spend +25 yrs in unix. I am so old, that I remember fighting (at my
> 40th) with linux 0.79, I think....
>
> However, I am questioning if this is what a programming language should do.
Stop thinking of bash as a programming language. It is a command shell.
Pipelines invoke multiple processes simultaneously. That's their purpose:
to run a bunch of things in parallel, with linked input/output. Each
process is just that -- a process. A full-blown separate running program
with its own PID, its own private memory and file descriptors, and so on.
Moreover, the behavior of bash is constrained by 40+ years of unix shell
history. It implements the feature set specified by POSIX, as well as
doing its best to be backwards compatible with older versions of itself,
and to a much smaller extent, with ksh and sometimes even csh.
If you want a shell that breaks out of that mold and does things in a
new way, then perhaps you want zsh.
If you want an interpreted programming language instead of a shell,
there are a bunch to choose from.