[plug] Bash "Processing" Script
Bernd Felsche
bernie at innovative.iinet.net.au
Fri Jun 11 15:35:02 WST 2004
On Fri, Jun 11, 2004 at 01:53:51PM +0800, Jay Turner wrote:
> > On Friday 11 June 2004 12:35, Jay Turner wrote:
> > > > Notwithstanding that this won't actually tell you that dd is
> > > > actually doing its thing:
> > > > ( while : ; do sleep 3 ; echo -n "." ; done ) &
> > > > dotter=$!
> > > > dd if=/dev/the_ universe of=black_hole bs=1planet
> > > > kill $dotter
> Bernd said:
> > The shell's ":" is short-hand for "true", so
> > while :
> > will loop forever, at least until there's a break or exit inside the
> > loop.
> >
> > $! is the process ID of the last process put into background.
> >
> > > I have not encountered them before in my bash experience..
> I have successfully implemented your code and it works fine.
> Unfortunately, I am one of these people who needs to understand
> why something does what it does and not be happy just with the
> fact that "it does".
> Your use of "shorthand" bash is still a little confusing for me,
> in that I still code the long way
> while [ true ]
Incorrect syntax.
while true
is correct
while :
is quicker to type.
> do
> sleep 3
> echo -n "."
> done
>
> Am I reading it correct that the 'while' is in the background
> printing dots, until we kill the 'while' process which won't be
> done until after dd has finished?
> If this is the case I am right in assuming that the brackets allow
> us to group those statements together and have them all put into
> the background?
The brackets are technically redundant because the statement starts
with "while" and is terminated by "done"; but the brackets add to
readability (believe it or not). Brackets are used in this context,
to create a sub-shell, which the & causes to run in background.
Additional statements can be run in the same sub-shell by placing
them before or after the while ... done statement; as required.
> Can this be expressed in the "long way" of coding?
I doubt it. The "&" is the only way of sending stuff into the
background. The "(" is the only way of creating a sub-shell.
I could expand the thing over several lines with appropriate
indents. For simple loops, that doesn't help with readability and
eats up too many display lines.
--
/"\ Bernd Felsche - Innovative Reckoning, Perth, Western Australia
\ / ASCII ribbon campaign | I'm a .signature virus!
X against HTML mail | Copy me into your ~/.signature
/ \ and postings | to help me spread!
More information about the plug
mailing list