Shell tips and tricks

Steven W. Orr steveo at syslang.net
Wed Oct 31 13:35:07 EDT 2007


On Wednesday, Oct 31st 2007 at 13:13 -0000, quoth Paul Lussier:

=>"Steven W. Orr" <steveo at syslang.net> writes:
=>
=>> On Wednesday, Oct 31st 2007 at 10:39 -0000, quoth Paul Lussier:
=>>
=>> =>"Ben Scott" <dragonhawk at gmail.com> writes:
=>> =>
=>> =>> On 10/7/07, Steven W. Orr <steveo at syslang.net> wrote:
=>> =>>
=>> =>>> I got a million of 'em ;-)
=>> =>>
=>> =>>   So keep going!  I'm trying to encourage the sharing of
=>> =>>   information, here.  :)
=>> =>
=>> =>And someone ought to collect 'em all onto the wiki somewhere :)
=>>
=>> Seriously, what would you like to know?
=>
=>It's tough to say what you'd like to know when you don't know what you
=>don't know.
=>
=>I just really enjoyed this thread and would like to see the discussion
=>continue.

Ok. In that vein, I have two areas that I personally find interesting.

1. The area of *proper* bash initialization. How people set up their init 
files is an area of universal shame.

2. How to write scripts that do what the shell is capable of with (more) 
minimal callouts to external programs. This is more than turning things 
like cat fn | grep into grep < fn. Good things happen when people get more 
comfortabler with looking constructs, signals, advanced descriptor 
management, to name just a few.

Just for starters, one things I see on a pretty regular basis is this 
erroneous construct:

foo=44
p1 | while read line
do
    dosomething
    foo=$((foo + 1))
done
echo "foo = $foo"

Given (let's say) 5 lines of output from p1, what will it print?

The winner gets to stay after school and clap out the erasers. If you 
already know it, please don't spoil. :-)

-- 
Time flies like the wind. Fruit flies like a banana. Stranger things have  .0.
happened but none stranger than this. Does your driver's license say Organ ..0
Donor?Black holes are where God divided by zero. Listen to me! We are all- 000
individuals! What if this weren't a hypothetical question?
steveo at syslang.net


More information about the gnhlug-discuss mailing list