Switching from tcsh to bash?
momerath2003 asks: "With the advent of Mac OS X 10.3 Panther, Apple will switch its default shell from tcsh to bash (in order to conform more to the newer Linux trends). A lot of Mac power users will want to know how to make the switch, especially if they use such tcsh-specific extra files as the login/out scripts in the /usr/share/tcsh/examples directory (they automatically set up some aliases and can automatically read aliases from a specific file, among other things). So, how do we all adapt? What are some ways to emulate the behavior of the example files, and what differences are there between the bash and tcsh shells?"
>> You can always edit /etc/passwd
> Why not use the command designed for this sort of thing, "chsh"?
Since chsh updatesOne thing that helps in bash is shell functions, because in bash aliases don't take command line arguments (unless my copy of Unix Power Tools is wrong).
.bashrc):
.; }
Here's a couple examples of shell functions. I use these to put and get files to/from my notebook from my desktop (put these in
nb-put () { scp $1 me@192.168.0.9:/home/me/$2; }
nb-get () { scp me@192.168.0.9:/home/me/$1
So then to get a file I just do nb-get <filename>
Another thing that is nice to know is how to do for loops from the command line in bash. Not that it's hard, it's just different from tcsh:
for n in 1 2 3; do echo $n; done
Google "bash tcsh differences" yields:
"UNIX shell diferences and how to change your shell."
If you are worried about scripts, something like:
#!/bin/tcsh
Should appear on line one of the script.
Jesus was all right but his disciples were thick and ordinary. -John Lennon
And today, I'm left contemplating whether I should change my default shell in Linux to tcsh. But that would mean to change lots of files:
/bin/sh
Just imagine, you donwload something nice, do "./configure" and - voila - syntax error.
Huh? configure scripts should have
#!
as its first line, so it really shouldn't be a problem. (/bin/sh is usually just a link to bash on Linux systems.)
K.
As you mentioned, chsh will not work.
"I'll say it again for the logic-impaired." -- Larry Wall.
% setenv PATH ${PATH}:/usr/local/bin
/bin:/usr/bin:/usr/local/bin
% echo $PATH
% unsetenv PATH
And bash:
$ export PATH=$PATH:/usr/local/bin
/bin:/usr/bin:/usr/local/bin
$ echo $PATH
$ unset PATH
There are other differences, of course, but it's a start.
"I'll say it again for the logic-impaired." -- Larry Wall.
Wow, flashback to 1995, when *I* transitioned from tcsh to bash. I had grown up on older Sun boxen where csh/tcsh was the prefered shell, but as I started using other Unices like Linux and AIX and as I started writing more shell scripts (especially little one-off scripts in interactive sessions), I decided to make the jump to bash.
All in all, bash is a better shell, especially for scripting. Back then tcsh was more configurable and usable, but by now I think tcsh has fallen behind. Anyway, there is a one-to-one mapping between most tcsh and bash features. The only diffence is the syntax: export X=Y instead of setenv X Y, alias foo="bar" instead of alias foo "bar".
When I switched, the two things I missed the most were tcsh's programmable completion, which is only matched by bash in version 2, and the method of doing a reverse search of the command history (tcsh's esc-p vs. bash's esc-r).
There are lots of great sites on getting the most from bash; here are a few good starting points:
ftp://ftp.cwru.edu/pub/bash/FAQ
http://www.caliban.org/bash/index.shtml
http://www.deadman.org/bash.html
What, no bash-vs-tcsh flames yet?
After using tcsh for about 5 years, I gradually moved to bash everywhere. For me, there were a few annoyances I was glad to be rid of:
( cmd > file.out 2> file.err)
ls -aFl $(find $(locate xterm) -type f -perm -a+x)
for file in $files; do mv $file $file.old && echo "$file moved"; done
Otherwise, I have made my shell environments pretty similar, to the point that I wouldn't readily notice the difference.