Shell tips and tricks
VirginSnow at vfemail.net
VirginSnow at vfemail.net
Wed Oct 31 14:21:29 EDT 2007
> Date: Wed, 31 Oct 2007 13:35:07 -0400 (EDT)
> From: "Steven W. Orr" <steveo at syslang.net>
> 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"
Did you intentionally leave the "$" out of "$foo + 1"?
Things I think may be worth studying:
(1) Managing file descriptors on the command line. What's already
open? What's open read-only, read-write, etc.?
(3) Here-documents and here-strings. How is this here-document going
to be munged? (i.e., What the heck is going to be substituted
in my hear-document?)
(4) All that ${%%:-//} funny variable parsing stuff. (Good
replacement for some calls to cut/sed.)
(5) Variable scope (see above riddle).
(5) Using /dev/{tcp,udp}. Save calls to netcat.
(7) Shell options? What are those?
More information about the gnhlug-discuss
mailing list