From Bash To Z Shell 214
From Bash to Z Shell: Conquering the Command Line | |
author | Oliver Kiddle, Jerry Peek, and Peter Stephenson |
pages | 472 |
publisher | Apress |
rating | 9 |
reviewer | Raymond Lodato (rlodato AT yahoo DOT com) |
ISBN | 1590593766 |
summary | An in-depth look at the functionality of bash and zsh. |
A *nix-style shell is available on a number of platforms, so the authors chose not to limit themselves to just one, such as Linux. The techniques they discuss can be used in Unix, as well as under Windows using cygwin.
In case you're not overly well-versed in shell handling, the first part of the book does a pretty good job covering all of the things a typical user might want to do. Basic command editing, I/O redirection, jobs, processes, and some simple scripting are all covered. For many users, this is also as far as they would like to go. However, reading a little further yields treasure.
The next part delves into bash version 3.0 and zsh version 4.2, both freely available on the Internet. In addition to more sophisticated command line editing techniques, the authors also delve into the misty realms of re-binding keys. A great many users find themselves typing the same sequences over and over again. While sometimes a script makes sense to encapsulate these sequences, sometimes you want to simply enter some text and that's where a key binding makes sense. One example given in the book for zsh is bindkey -s '\C-xt' 'March 2004\eb' . After the binding, typing CTRL-x t puts the string 'March 2004' onto the command line, and moves the cursor under the '2' so you can insert the day of the month. That's a very simple example for a very powerful facility. A good chunk of chapter 4 is spent on showing how to make the most of bindkey (or its bash cousin 'bind').
The next few chapters cover common topics of prompt strings, file/directory globbing, and shell history. Then, significant press is given to the subject of pattern matching. Many people understand basic pattern matching and regular expressions, but From Bash to Z Shell goes into careful detail, with many examples from both bash and zsh, to contrast the (minor) differences between these two powerful shells. The next chapter discusses command line and file/directory name completion, a topic usually glossed over in other texts. Finally, job processing wraps up Part 2.
The third and final part of the book deals with extending the shell using variables, scripts, and functions. Here's where we get into the nitty-gritty. The first two chapters go over familiar territory: shell variables and shell programming. The chapter on programming is easy to follow, and I suggest you try the examples as you go to get the most out of it. The last two chapters focus on topics frequently overlooked: editor functions, and completion functions. Editor functions allow you (with bind[key]) to define new capabilities to use while editing the command line. This is where a true power user can shine, creating a suite of new functions to speed his/her use of zsh or bash. Completion functions work in defining new ways for the shell to complete a command, file name, or directory, based on a user-written function. Honestly, it's not something I would tend to use, but the capability is intriguing.
All in all, From Bash to Z Shell provides a frequent shell user with a plethora of new insights into customizing the bash and zsh shell programs to fit his/her tastes. The authors have filled a void in tackling the subject of customizing the shell rather than just simply using it. I would have liked to see more coverage of some of the more standard uses of the shells, just so the book could be a more complete reference, rather than the specialized one it is. Specialized or not, there is a lot offered here, and you couldn't go wrong getting this book.
You can purchase From Bash to Z Shell: Conquering the Command Line from bn.com. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.
Which one? (Score:4, Funny)
Re:Which one? (Score:4, Funny)
Re:Which one? (Score:4, Funny)
Wouldn't it have been better... (Score:5, Insightful)
Re:Wouldn't it have been better... (Score:3, Funny)
Technically, that should be either "From ash to zsh" or "From A to Z Shell".
Re:Wouldn't it have been better... (Score:3, Informative)
Technically that's not right either because ash is the Adventure Shell! [ifarchive.org]
Re:Wouldn't it have been better... (Score:2, Informative)
Re:Wouldn't it have been better... (Score:2)
No, ash is both. The adventure shell predates the almquist shell by many years. They both happen to use an executable named ash, though.
Re:Wouldn't it have been better... (Score:4, Insightful)
Re:Wouldn't it have been better... (Score:3, Informative)
Re:Wouldn't it have been better... (Score:4, Interesting)
I say this because I once spent months fixing hundreds of scripts in an embedded system after the OS vendor upgraded from bash-1.x to bash-2.x. If you don't need the extras that bash gives you, then use the #!/bin/sh shebang and make sure it works with sh/ash/ksh.
Re:Wouldn't it have been better... (Score:2)
Oooo, religious wars!! (Score:5, Funny)
zshell sux!! bash rules!!
Re:Oooo, religious wars!! (Score:2, Interesting)
Re:Oooo, religious wars!! (Score:2, Troll)
My God. Surely you're joking.
How, exactly, is tcsh more professional ? And more professional than what? Csh? Using Emacs hexl-mode as a shell is more professional than csh.
Re:Oooo, religious wars!! (Score:5, Funny)
I once caught bash selling my personal files on ebay. Also, tcsh cured my grandmother of rheumatoid arthritis.
In related news, emacs is more articulate than vi, three-button mice are sweeter than one-button mice and perl grepped your sister.
Actually, that last one is true
Some info (Score:2)
Re:Oooo, religious wars!! (Score:3, Informative)
Long answer: I don't think most tcsh users use it for its programming ability. Instead, it tends to be useful as a solid interactive shell. Its general "feel" tends to be more solid than bash, owing partly to the fact that bash has a lot of built in key-shortcuts that tcsh doesn't. Of course, once you're used to being able to double tab for a directory listing, it's kind of hard to give up.
Re:Oooo, religious wars!! (Score:3, Informative)
Re:Oooo, religious wars!! (Score:2)
Long answer: I don't think most tcsh users use it for its programming ability. Instead, it tends to be useful as a solid interactive shell.
I agree -- back when I started using the tcsh, my options were the (real) Bourne shell, the basic csh, and I think that was about it (Gould Unix). When I was young and dumb, I'd write scripts in tcsh syntax, but only for really basic things. But the real merits of the tcsh come in interactive mode -- the completion was a revelation, and the ability to do quick loop
Re:Oooo, religious wars!! (Score:2)
-tab completions
-color code
-long ass history list
Re:Oooo, religious wars!! (Score:2)
Re:Oooo, religious wars!! (Score:3, Informative)
Directories are bold
Links are italic
I think there were also underlines for something, but hell if I can remember what.
Here's some links to help you on your way:
http://www.webservertalk.com/archive109-2004-3-
http://sunsite.nus.sg/pub/LDP/HOWTO/min
Re:Oooo, religious wars!! (Score:3, Interesting)
Re:Oooo, religious wars!! (Score:3, Funny)
The big bold red color that tells me a symlink is broken.
Outside of that one use, I cannot name a another time when I have thanked the color granting shell overlords.
Re:Oooo, religious wars!! (Score:2, Informative)
Colors? Fonts? Feh. You kids and your fancy terminals.
The "standard" is to alias ls to 'ls -F'. This appends * to executables, / to directories, @ to symlinks, = for sockets, and | for FIFOs. Works on any terminal.
Re:Oooo, religious wars!! (Score:2)
Except for the fact that I absolutely hate that output. It drives me nuts seeing those characters there. IMHO, it looks worse than colors. Give me a Solaris terminal any day.
Re:Oooo, religious wars!! (Score:2)
Re:Oooo, religious wars!! (Score:4, Interesting)
Syntax highlighting can give you a great deal of information. I have written a shell called fish [no-ip.org], that syntax highlights the commands as you are typing them. What I find useful about this is that fish colors potential errors in red. Mistyped commands, non-existant options, reading from non-existing files and loads of other errors can be identified by just glancing on your screen.
</shameless plug>
Re:Oooo, religious wars!! (Score:2)
Re:Oooo, religious wars!! (Score:2)
Discuss among yourselves.
Re:Oooo, religious wars!! (Score:3, Interesting)
Everytime I try to understand a *nix shell parm I have to switch to Emacs and ask the Doctor....
Re:Oooo, religious wars!! (Score:3, Funny)
Re:Oooo, religious wars!! (Score:3, Funny)
Re:Oooo, religious wars!! (Score:2)
Re:Oooo, religious wars!! (Score:2)
More info on TECO for those who care.
http://c2.com/cgi/wiki?TecoEditor [c2.com]
http://almy.us/teco.html [almy.us]
Which shell is best for you? (Score:5, Informative)
bash, mostly just because of historical reasons.
Speaking of different shells in general. Here is a very handy list
that can help you pick which shell is best for you. This is not meant
to start a war over which shell is better but is just meant to help
pick the shell that is best for you:
http://www.unix.com/showthread.php?t=12274
Just thought it would be helpful.
zsh plug: Recursive file completion (Score:5, Interesting)
I used to find myself using find a lot -- mostly for handling files in subdirectories, and/or for selecting files based on metadata of various kinds. But zsh makes find almost totally unnecessary: it has a simple but very powerful syntax which extends the simple '*' and '?' file completion to allow selection by size/date/type/&c, exclusion lists, user-specified ordering, and most usefully it can select files in subdirectories too. And because it's right there in the shell, the results are easy to use without that awkward -exec syntax. I don't think I've used find once since switching to zsh!
I really don't understand why it hasn't become more popular. It's free and open source; it can mimic other shells (notably, ksh), and it ships with systems such as Mac OS X.
Re:Which shell is best for you? (Score:2)
There are way more new features that could be added to it. Especially from zsh. Many of zsh's strongest features are not even mentioned.
For ksh, it is only looking at ksh88 which is what comes with Solaris, AIX etc. ksh93 has many more features related to scripting, some of which this book mentions. Since the release of version 93q earlier this year, ksh is now licenced under the CPL making it properly open source so you can even get it in Debian.
What a crappy title... (Score:2, Funny)
What? No "Making vi Sane?" (Score:2, Funny)
Re:What? No "Making vi Sane?" (Score:2, Funny)
Don't believe it. (Score:2, Funny)
Oh sure, those dark alleys might seem to be the shortest route to your destination, but really their just a quick path to a mugging.
W00t! Finally! (Score:5, Interesting)
I like the Advanced Bash Scripting Guide [tldp.org] quite a bit, but I'd also like to learn about other shells, without reading through a mountain of manpages, nor reading through webpages, and just for general interest while riding the El (not because "I need to do x!").
$20 at bookpool (Score:2, Informative)
Perhaps I'm evil, not supporting bn.com but, it's a massive difference in price - cheap enough to pick up casually.
Re:W00t! Finally! (Score:2)
Re:W00t! Finally! (Score:3, Informative)
What about COMMAND.COM? (Score:5, Funny)
Quickly runs out of the room and hides.
Re:What about COMMAND.COM? (Score:2)
Sorry, command.com is so lame I don't think it can even handle a simple command like that.
Try it yourself ;-) (Score:2, Funny)
Oh my god!!! (Score:2)
shell war game..... (Score:2, Funny)
also a good book (Score:4, Informative)
The book is mostly on bash, and c-shell.
SASH? (Score:2, Informative)
ARCS (Score:2)
SASH is pretty slick, actually.
bash rules! (Score:2)
The flip-side is that students who don't know how to use the different shells are probably screwed anyway once they get into the real world. Go figure.
Re:bash rules! (Score:3, Informative)
If I'm thrown into a shell I don't like, I just type "bash"<enter> and that's that. If the students can't figure that one out, they really are screwed.
Re:bash rules! (Score:2)
Re:bash rules! (Score:2)
Re:bash rules! (Score:2)
Re:bash rules! (Score:2)
Go buy some champagne, to celebrate the fact that I have somehow invented a time machine that will take me back to 1993.
Re:bash rules! (Score:2)
Because of scripting, even the slightest difference between shells becomes very important, but for interactive use the differences often become trivial. Anyone who is familiar with any sort of unix shell can "handle" bash, even if they a
Re:bash rules! (Score:2)
It was an informal study (probably an end-of-semester survey) conducted by the department for it's own internal use. The instructor mentioned it during the linux course on why we were using only bash for the scripting excercises. I think the real problem is that some students
Re:bash rules! (Score:2)
Why I love zsh (Score:5, Interesting)
One thing I have never been able to do successfully is to emulate the old ksh's ability to hit Esc-Esc on the command line and get popped into vi with the last command in the history file ready to be edited. It was such a boon to rapid development of shell scripts. Then again, I don't do as much shell scripting these days, so its probably no great loss.
If anybody knows how to do this, esc-esc thing in zsh and can tell me, I'd be really grateful.
Re:Why I love zsh (Score:2)
put that in your ~/.zshrc if you always want vi keys enabled. Or you could have bought the book that was reviewed.
Re:Why I love zsh (Score:2)
My question is, how do I make the command esc-esc put the last command in the history file into a full vi session?
Or, in simpler terms, how do I make esc-esc execute the 'fc' command? I've tried lots of clever ways over the years, none of them have worked.
Re:Why I love zsh (Score:2)
Are you thinking of 'ESC-k' (or 'ESC-up-arrow') which opens the commandline history? That's like the 'fc' command, without opening a vi session.
In the ksh93, the vi command-line editing actually consisted of some vi-style commands, some ksh-only style commands, and some emacs-style.
I think the ESC-ESC was a ksh-only command, or it was some common binding on some OSs... but it wasn't universal. ksh93 was annoyingly different on Solaris 8 vs HPUX or AIX. Drov
Re:Why I love zsh (Score:2)
Esc-Esc might have been a ksh-only command, which would explain why I can't get it work with zsh. It really changed how I protyped shell scripts and probably helped me move to perl (if I have to open the editor window anyway, etc...)
Re:Why I love zsh (Score:4, Interesting)
bindkey -s '\e\e' 'fc\n'
This is with a freshly updated debian 'unstable' system,
zsh --version
zsh 4.3.0-dev-1 (i686-pc-linux-gnu)
Re:Why I love zsh (Score:2)
That works! It must have been fixed sometime since 4.0 (which I think was when I finally abandoned hope).
Re:Why I love zsh (Score:2, Informative)
Best shell (Score:5, Funny)
New ideas (Score:3, Informative)
I think both zsh and bash could use a redesign. The syntax is crufty, with stupid variable assignment syntax ('foo = bar' is not the same thing as 'foo=bar'? '$foo' is not the same thing as `$foo` or "$foo"?), insufficient tab-completion support and very few features enabled by default.
I have written a shell called fish [no-ip.org]. It has lots of new features [no-ip.org]. Check it out.
</shameless plug>
Suggestion (Score:5, Funny)
}><(([@>
for reasons which should be obvious.
Re:New ideas (Score:2)
will give you the value of $foo (say, "bar").
will return the string "$foo"
will give you the output of the command, if the value of foo is set to a recognized command. Useful for combo commands.
These are convenient, and not too hard to remember. Just out of curiosity, how are these things done in fish?
Re:New ideas (Score:3, Informative)
In bash:
$foo gives you the contents of variables foo as a list of space-separated strings. "foo bar" becomes "foo" and "bar".
"$foo" gives you the contents of variable foo as a single variable. "foo bar" remains "foo bar".
'$foo' gives you the string "$foo".
`$foo` executes the command pointed to by the variable foo in a subshell. If foo has the value "ls" executes the "ls" command.
In fish:
$foo gives you the contents of variable foo as a single string, "foo bar" remains "foo bar".
"$fo
Re:New ideas (Score:2)
If the value of $foo is "bar", then $foo, "$foo", and '$foo' all give the error "bash: bar: command not found"
and
both return "bar."
returns "$foo." If $bar has the value "ls", then
will search for 'foo' in whatever is listed in your directory.
My basic point was, the quoting mechanism is no more complicated than the (US) English sentence: I said, "He explicitly said to me, 'don't feed them after
Re:New ideas (Score:2)
Right, but consider variables with spaces. Here's what the OP is getting at:
produces output:
On the other hand, 'fish' tries to avoid this, and presumably would produce:
Re:New ideas (Score:2)
Like a previous poster pointed out, echo $foo does not do what you think it does, it just happens to work in your example since your string does not contain spaces.
Re:New ideas (Score:2)
If you write $foo when foo="foo bar", it does not "become" two separate strings. Variable interpolation in shells is just a textual search-and-replace. So if you write:
$ ls $foo
Here's what the shell does:
1. Perform variable interpolation: now the command is ls foo bar
2. Interpret the command. It splits the command into parameters using the contents of IFS, which is set to space, tab, and newline by default. So now the command
Re:New ideas (Score:2)
Re:New ideas (Score:5, Funny)
Re:New ideas (Score:2)
Re:New ideas (Score:2)
Re:New ideas (Score:2)
for i in a b c; do; echo $i; done
is a syntax error (too many ';') is also stupid.
I _know_ that variable assignments are whitespace sensitive, but in my opinion no good language should be.
I don't like the fact that if bloc
Re:New ideas (Score:2)
is a syntax error (too many ';') is also stupid.
It isn't an error in zsh.
I _know_ that variable assignments are whitespace sensitive, but in my opinion no good language should be.
So how does fish allow you to run a command named foo with equals as the first argument? Do you need to quote the equals.
Do you really need semi-colons after all those lines?
Re:New ideas (Score:2)
From what I've looked at of the documentation, it does have a lot of optional csh (that is what tcsh is ultimately based around, no?) derived semantics (many features have both bash and csh styled ways of accessing them). But I think it leans more heavily toward the bash/ksh end of things, so I
Unicode (Score:5, Insightful)
I know they started working on it in february, at least more actively then before. So it will come eventually. Once the internals are done they will move on to the line editor.
Untill then, it still "eats" my prompt when backslashing over multibyte characters...
Wicked! (Score:5, Informative)
What a timesaver! I start so many commands with In all seriousness, though, I'd like to stick my suggestion in here: Wicked Cool Shell Scripts [intuitive.com] is a charming little read and the scripts are all on line!
TI-85 (Score:2)
Mr Old fashioned (Score:3, Insightful)
#!/bin/sh 4 LIFE!
Re:Mr Old fashioned (Score:2)
Re:Mr Old fashioned (Score:3, Insightful)
Re:Mr Old fashioned (Score:3, Interesting)
There is however another problem related to the one you outline above. bash, zsh and probably most of the other shells in you
IPython (Score:5, Interesting)
In the 'pysh' mode, it acts as a fully functional system shell, even on Windows. Bash and friends suck on windows, but IPython truly shines there. It really makes the command prompt use of Windows feasible, with bash like filename completion etc. Being able to extend it with python functions (as opposed to separate scripts) is a killer feature as well.
I've actually replaced the command prompt launchers on my KDE desktop with 'ipython -p pysh' launchers.
Topic icons (Score:2)
Re:insensitive clods! (Score:2)
Re:ZSH rocks except for one feature (Score:3, Interesting)
If that doesn't help let me know. Or mail zsh-users. I've never had a problem with it and it has always worked well.
I also set these options:
The last of those allows history so be shared between concurrently running shells.
Re:ZSH rocks except for one misfeature (Score:3, Insightful)
To get a goob tab completion, with a good pager, etc, you need another boatload of commands. You will also want to redefine some keyboard shortcuts to more powerful versions of the same commands and install a few nifty add-ons.
So suddenly you have spent a few hours creating a 100+ lines long configuration file jus