My preferred Unix shell is bash; if that's not
available, I'll use zsh, ash, ksh or plain sh. I really don't like csh
or tcsh very much at all; they make it difficult to write scripts at the
prompt (and shouldn't be used for non-interactive scripting at all; see
Tom Christiansen's "Csh
Programming Considered Harmful" for an impassioned rant on why this
is a bad idea). My Linux system doesn't have
a /bin/csh, and I haven't missed it yet.
rc is another nice shell, based on the Plan 9 shell. Its
syntax and features are better suited to programming than the Bourne
shell.
For more bash tips, have a look at deadman.org's bash tips page.
-
If you're renaming a file with a long filename where the change is
small, you can use
{}to your advantage:mv /some/long/name/{oldfile,newfile}mv /some/long/name/spelt-{u,i}ncorrectly -
If you want to do something to every line of a file in bash, you can use
a
whileloop withread, which puts each line into the$REPLYvariable:while read ; do echo $REPLY | sed 's/foo/bar/g' ; done <file -
You can also read lines from several files by using multiple file
descriptors:
while read a ; do read b <&3 ; echo $a $b ; done <file1 3<file2 -
Since
rmdironly works on empty directories, you can usermdir *to prune empty directories that are in the current directory.