Ted Leung on the air: Open Source, Java, Python, and ...
I have a long history with UNIX. My first exposure was to 2BSD on the VAX. The shell on that system was the C-Shell. When I got to MIT and started working at Athena, I was using tcsh. During my years at Brown, I discovered zsh, which I am using to this very day.
Most of the time I picked up what I needed to know by reading the man pages for the various shells, and it's been a very long time since I read a book on a shell. I think that the only shell books that I own are The UNIX Programming Environment and The KornShell command and programming language. Recently, I've wanted to do more stuff with zsh, particularly around command completions. zsh is on it's second completion system, and I found the manual pages pretty tough going. So I finally broke down and got a copy of "From Bash to Z Shell: Conquering the Command Line". Two of the authors are zsh developers, which made me very hopeful about the book.
I was not disappointed. Maybe it's just that I needed a shell refresher in general, but I got a lot out of the book. Here are a few of the things that jumped out from my notes:
- redirecting the output of a for loop
- the CDPATH variable (cd searches this path)
- accept-line-and-down-history [Ctrl-o] (make it easy to execute sequence of lines from the history)
- push-line-or-edit and the zsh buffer stack (push fragments of a command line onto a stack)
- The !? history command (search history for nearest match)
- The two argument form of the cd command (replace arg1 in $cwd w/ arg2 and cd there)
- Matching numeric ranges (understands numbers)
- bashcompinit (emulate bash completions commands - allows use of bash_completion project)
- Partial completion (cd /u/lo/b <tab> to cd to /usr/local/bin)
- Process substitution ( emacs =(indent -st < file) - sends output of indent to emacs)
- zsh associative arrays (very useful)
The chapters on zsh completion alone were worth the price for me.
For those new to zsh, Yammer has some other zsh examples.
* redirecting the output of a for loop
(for i in *; do echo $i; done) |less
* the CDPATH variable (cd searches this path)
Easy to do with a function in bash.
* accept-line-and-down-history [Ctrl-o] (make it easy to execute sequence of lines from the history)
Kinda useful, I guess. But if you're doing a dependent sequence of commands, you should put them in a single command line with &&
* push-line-or-edit and the zsh buffer stack (push fragments of a command line onto a stack)
#partial command
* The !? history command (search history for nearest match)
man bash, read the HISTORY section.
* The two argument form of the cd command (replace arg1 in $cwd w/ arg2 and cd there)
Easy to write as a function.
* Matching numeric ranges (understands numbers)
* bashcompinit (emulate bash completions commands - allows use of bash_completion project)
* Partial completion (cd /u/lo/b <tab> to cd to /usr/local/bin)
cd /u<tab>/lo<tab>/b<tab>, and it's a lot more likely to get you where you wanted.
* Process substitution ( emacs =(indent -st < file) - sends output of indent to emacs)
indent -st <file |emacs, or indent >out && emacs out
* zsh associative arrays (very useful)
Sure. Though you can use numeric arrays in bash, and ksh has associative arrays. In no case should you be doing complex programming in a shell script!
A good resource for sh, bash, and ksh is Stephen Kochan's Unix Shell Programming.
Posted by Mark Hughes at Mon Jun 20 13:05:09 2005
I didn't by any means list all the differences between zsh and the other shells. I listed what was new to me. The book does point out where bash and zsh can do the same thing, albeit with different syntax.
I started using zsh because at the time, it's interactive features were way ahead of other shells. The bash folks in particular have been doing good work to catch up, but even when I tried bash_completion recently, the completions were not as good as the ones for zsh. One strong point of bash is that the bash_completion project is separate from bash, so completions get updated faster, whereas you have to pull a new zsh release in order to get newer completions.
For anything longer than a few lines, or that might run more than a few times, I definitely pull out Python.
Posted by Ted Leung at Tue Jun 21 01:21:18 2005
for i in *; do echo $i; done |less
I considered switching to zsh. However, Bash is much more widespread and the default on most of the many accounts I use. Learning the POSIX standard shell is time well spent, IMO. Most shells implement it pretty well (e.g. bash, zsh, sh on most machines) and it's pretty powerful.
Posted by Neil Schemenauer at Tue Jun 21 14:55:04 2005
RPROMPT=%~
and see for yourself. It even removes it self from display temporarily if you type a long command. I don't know if Bash has gotten this feature since I switched from zsh (in 2001).As for the file name generation using <x-y> I use it often, especially when moving photos named something like dsc12345.jpg.
The
EXTENDED_GLOB
option is sometimes usefull, and the NUMERIC_GLOB_SORT
option is just nicer than the default alphabetic sorting.Finally, Glob Qualifiers are great: with
*(.)
I get all files in the current directory. With **/*(/)
I get all subdirectories (recursively).In short: I love this shell! :-)
Posted by Martin Geisler at Sun Nov 6 03:33:17 2005
To insert a URI, just type it -- no need to write an anchor tag.
Allowable html tags are:
<a href>
, <em>
, <i>
, <b>
, <blockquote>
, <br/>
, <p>
, <code>
, <pre>
, <cite>
, <sub>
and <sup>
.You can also use some Wiki style:
URI => [uri title]
<em> => _emphasized text_
<b> => *bold text*
Ordered list => consecutive lines starting spaces and an asterisk