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?"
I imagine the "power users" who use tcsh will... wait for it ... here it comes ... SWITCH BACK TO TCSH!
Really, it's no big deal. They are both fine shells. Tcsh is rotten for programming but that doesn't affect most people.
I already installed fink, and use Bash now. So no switch here.
First thing I did when I got my mac, was install fink, and call bash. All my scripts and aliases are for Bash. Glad to see OSX will using bash native, since every unix box I have uses bash (or ksh).
Now if I could just get a better terminal program like konsole to run native, instead of under X. iTerm is ok, but still has some quirks, thou it does have nice transperancy, gotta love that icandy.
You can always edit /etc/passwd and change it from bash back to tcsh. Or maybe chsh works in OS X? As far as alaises, etc. go there is tons of help on the web, and of course you could always "man bash".
Don't blame me, I voted for Kodos
echo "tcsh" > .bashrc
life is...you know...tough...or something
Put "set editing-mode vi" into your
Healthcare article at Kuro5hin
RTFM :D
/etc/bashrc
/etc/profile
~/.bashrc
~/bash_profile
RedHat spoiled me, so I change my prompt on any machine I have that's bash capable.
export PS1='[\u@\h \W]$ '
By the very nature of *nix environment, one should be able to switch shells without much problem. Leftover habits when coding may keep creeping in, but consistency is key. If you've done any awk/sed/csh/bash/ksh like programming, one realizes that not all the world is one language - yet.
Presupposing that people will have "trouble" switching is kind of assuming we're dealing with a "who moved my cheese" user seen more on corporate win32 desktops. Any techie worth their salt knows how to get a job done in a shell. Perhaps the most exasperating are the escape sequences. But one just see the runtime differences and plods through the changes. no magic here.
mug
One 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."
Googling for "bash tcsh differences" yields:
h ell-diff erences
"UNIX shell differences and how to change your shell"
http://www.faqs.org/faqs/unix-faq/shell/s
>Googling for "bash tcsh differences" yields:s hell-dif ferences
>"UNIX shell differences and how to change your shell"
>http://www.faqs.org/faqs/unix-faq/shell/
Did you even click on the link after your oh-so-helpful google didacticism?
That's one of the least helpful FAQ documents I've ever seen. Just a table of cryptically named commands. Scary. And I think the original post was aimed at Mac users, so this would be *really* scary for them.
Linux using Bash as the default shell is not a "newer Linux trend". As for the differences, there is a lot of information on each shell available on the web.
Google is your friend.
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
Mac OS X already includes /bin/bash, though not as the default shell. Sure, Fink contains a copy also (perhaps a newer one), but is not required.
/bin/bash.
First thing I do on any new Mac OS X box is to go into the NetInfo manager and change my (and root's) login shell to
Just run bash --tcsh scriptfile of course!
I don't understand why anybody would want to change bash to tcsh.
When I started playing with FreeBSD I was forced to used tcsh, since it is installed by default.
After some initial problems (like different keys for auto-completition and history filtering according to what you started to type) I actually started to like this style. 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:
Just imagine, you donwload something nice, do "./configure" and - voila - syntax error.
% 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
it would be nice if OS X actually let the user set the shell from the system preferences...on the other, anybody who cares will do it themselves and forget about it.
This may be a strange question -- my questions often are -- but why change just because the OS/X default changed? It's easy enough to change it back: I suspect there's a version of chsh(1), but even if there isn't, it's just the last parameter in /etc/passwd.
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.
Having used tcsh quite a lot (on Linux and Irix and Cygwin) and having to switch to bash, I have to say that 95% of the problem is that I am very used to typing "setenv", and also a lot of "sourced" type scripts that do nothing except setenv (ie we use lots of "source setup_foobar" to get around stupid programs that have conflicting requirements for environment variables)
A big help would be a simple alias for bash that makes setenv work like tcsh. Just put this in the default login or something.
If you find yourself writing C-shell-family script, consider a nice crack pipe and some hash brownies. Because you're fucking insane already. KIlling the rest of your brain cells would be a harmless mod. (I don't believe gmhowell to be one of these people; it just needed to be said.)
The C shell was written "to mimic the C programming language." What's the primary tool in the C programming language? Functions. What did csh remove that all other shells had? Functions. What are you supposed to use in their place?
Give me a fucking break. Teaching scripting in [t]csh is like teaching structured programming in cobol, or recursive programming in fortran77. I'd like to reuse my code, thankyouverymuch, not copy and paste it everywhere.
You cannot apply a technological solution to a sociological problem. (Edwards' Law)
# .bashrc
# User specific aliases and functions
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
alias exchange='rdesktop -l -g 1280x1024 -u paugros -d region6 localhost'
alias ajax='ssh root@216.177.28.62'
alias visa='netscape http://service.capitalone.com/'
alias cdrom='mount /mnt/cdrom && cd /mnt/cdrom'
alias cdrom1='mount /mnt/cdrom1 && cd /mnt/cdrom1'
alias floppy='mount /mnt/floppy && cd /mnt/floppy'
alias ucdrom='cd && umount /mnt/cdrom'
alias ucdrom1='cd && umount /mnt/cdrom1'
alias ufloppy='cd && umount /mnt/floppy'
alias ll='ls -lSh'
alias du='du -h'
alias ping='ping -U'
alias xxx='killall -9'
alias ftp='ftp -i'
alias df='df -h'
alias ls='ls --color=tty'
alias lsl='ls -lh'
alias lsa='ls -A'
alias lsal='ls -Alh'
alias lsla='ls -Alh'
alias rc='jed ~/.bashrc'
alias less='less -M'
alias c='clear'
alias a='cd ..'
alias d='pwd'
alias p='ping 216.204.0.33'
alias rcs='source ~/.bashrc'
#############
# LS_COLORS #
#############
# Directories = yellow
LS_COLORS=di="33;01"
# C source code and object files = white
LS_COLORS=$LS_COLORS:"*.c=37;01":"*.C=37;01":"*.h= 37;01":"*.H=37;01"
LS_COLORS=$LS_COLORS:"*.cpp=37;01":"*.o=37;01"
# Image files = magenta
LS_COLORS=$LS_COLORS:"*.JPG=35;01":"*.jpg=35;01":" *.gif=35;01":"*.tif=35;01"
LS_COLORS=$LS_COLORS:"*.tiff=35;01":"*.bmp=35;01": "*.xbm=35;01"
LS_COLORS=$LS_COLORS:"*.xpm=35;01":"*.ps=35;01":"* .png=35;01"
LS_COLORS=$LS_COLORS:"*.fts=35;01":"*.jpeg=35;01"
# Archive files = blue
LS_COLORS=$LS_COLORS:"*.gz=34;01":"*.tgz=34;01":"* .tar=34;01"
LS_COLORS=$LS_COLORS:"*.Z=34;01":"*.zip=34;01":"*. bz=34;01":"*.bz2=34;01"
# RPMs = red
LS_COLORS=$LS_COLORS:"*.rpm=31;01"
PS1="\[\e[1;37m\]\h:\w$\[\e[0;0m\] "
PATH=$PATH:$HOME/bin:/sbin:/bin/bash2:/usr/sbin:/u sr/local/bin:/usr/local/sbin:/
usr/games:/usr/local/games:./:/usr/X11R6/lib/xscre ensaver:/home/paul/dev/perl:/u
sr/java/j2re1.4.0_01/bin:
EDITOR=jed
HOME=/home/paulKNOTPLOT_HOME=/usr/local/knot
export LS_COLORS PS1 PATH EDITOR KNOTPLOT_HOME
unset LESSOPEN
#fortune -s
#echo
It's all going according to
Even vi is straining to keep up as I type this.
Don't you mean vi lite?
flask of ripe urine
pressed to bsd lips
bsd drink up
I would be interested to know what is motivating the shift exactly. I gather that the poster is not intending to use bash to write lengthy programs. On the other hand, it sounds like some other posters do use some variant of shell to write long programs. For what exactly? Is it really more convenient than using another scripting language? Part of the motivation for this question is that I have developed a little prototype optimizing interpreter for a shell-language subset (basically sh) and am looking for applications, especially where performance is an issue.
The first command to learn is ($) man bash ... apart from that it is alot easier to make files and run scripts with. Another essential command is ($) man man
I just hope the Apple guys include the man program and docs if not it will flop big time. Bash rocks!
OH THE SHAME I fell off the wagon and use sigs again!
what are we bashing now? ...
unix, linux, microsoft, macintosh, apple ][, amiga, commodore 64, broadband, dial-up, bbs, vi, emacs, sed, awk, grep, perl, openwindows, motif, xbox, nintendo, sega, atari, intellivision, rambus, sdram, intel, amd, via, nvidia, ati,
whatever happen to the rambus news on slashdot?
WhatMeWorry
Unless the assumption is that any significant portion of the OS X user base actually uses the shell, I doubt there will be many that even notice.
I still view OS X as a definite non-unix. It's right up there with say, windows+cygwin. A non-unix kernel with some unix userland stuff sprinkled on top.
And to address the "But it's the best integrated Unix desktop ever!" argument, tell me why the tar that ships with it breaks all the filesystem meta information (which many mac apps still rely on, in my experience). I've heard similar problems with the rest of the user space utils (i.e., cp)
Or, of course, the complete disregard for the Unix filesystem hierarchy standard
-transiit
1. You have too much disk space, and want a shell that's 50% bigger.
2. Setting environment variables via setenv is too intuitive, you'd prefer a stupid non-mnemonic command like "export" (to what?)
3. You'd rather run scripts in a huge shell than in a compact scripting language suited to the task such as python or perl.
4. You have a bizarre belief that your scripting language and your interactive shell need to be the same program.
5. You worship Richard Stallman.
GCHQ Quantum Insert installed. If only our tongues were made of glass, how much more careful we would be when we speak
So, if Apple's going to make me mess around to get a shell I don't actively loathe, I may as well consider all the possibilities.
So... which shell should I use, and why?
To give you some ideas for what I'm looking for:
- I don't care about scripting. If I want to write a script, I'll use a scripting language.
- Mnemonic commands are good.
- Good command-line editing that uses sensible keystrokes (e.g. Home and End work) is good.
- Small memory requirements and high CPU efficiency are very good.
GCHQ Quantum Insert installed. If only our tongues were made of glass, how much more careful we would be when we speak
That will start tcsh each time you ssh in, or start a Terminal window.
..and it will break sftp too, as sftp runs your login shell (and it's associated start up files) prior to starting the sftp after authenticating. Authenticated sessions will now hang with a mod as shown above.
-- I speak only for myself.
I think those of us with Mac OS X and half a klew already use standards compliant methods to make sure scripts work on any platform, i.e.:
a rch.COM.AU
#!/bin/sh -
echo "Hello World!"
exit 0
99.2% of people using Mac OS X prolly don't use a shell anyway.
With 18+ years unix I've gone from hard copy tty line printer consoles, to vt100's, wyse 75, wysel 180, to a cranky old toshiba 5200 plazma screen ( loved that ) running Xenix, then SCO, then 386/ix, and eventually BSD/386. I tried using a toshiba techra 8200 with windows 95, 98, 2000 and it was crap, then went to using an old Mac Powerbook 150 and never looked back - I've always had a mac around the place, but once I started using a mac, I found it the closest thing to having a sun workstation in a laptop, without the cli ( bugger ) - I even ran Apple's "Apple UX" BSD system once, but it was heavy on old mac's, even ran the tenon stuff - same deal.
So when Mac OS X 10.0 came out, I dropped everything and ran to the nearest ( yes, I said ran! ) shop, and got a 15 inch G4 and have never looked back. Now I can't understand why people run PC platform latop's with Linux when they can have the perfect world of a Mach kernel ( the best ), a FreeBSD core with the whole of the open source world at their feet, and everything I have ever needed that ran on Linux runs on Darwin just fine ( unless some moron has written pissy code and then they can get stuffed - I'll write it myself ).
Convert now - dump intel, bring your linux thinking, and run Darwin on PPC and see a brighter world!
++dez;
---
Dez Blanchfield
dez@blanchfield.com.au
http://WebSe
--- Dez Blanchfield http://WebSearch.COM.AU "Will work for bandwidth.."
I don't own a Mac, but I work with the art dept who do. Me being the computer guy they expect me to be able to fix things, even though my experience with OSX is *very* limited. Having looked through all the menus, and some of the program folders, I can't even seem to find the shell in the first place - where the fsck is it?
I mod down anyone who says "I will be modded down for this", regardless of the rest of their comment
On a POSIX system, /bin/sh is required to be a POSIX-compliant shell (or, as usually happens, a symlink to one). As far as I know, no GNU/Linux distribution has actually paid to be certified as POSIX-compliant, but in order to be compatible with other Unixes, they all aim for POSIX compatibility.
/bin/sh is a symlink to /bin/bash, although there are exceptions (the Debian install floppies use ash, a smaller and less featureful POSIX shell, because bash wouldn't fit). I understand some BSDs link /bin/sh to /bin/ksh instead.
bash, ksh, and ash are POSIX shells (each supports a superset of POSIX functionality), but csh isn't; as a result, portable shell scripts starting with #!/bin/sh should never get run under csh anyway.
In most Linux distributions
setenv () { export $1=$2; }
unsetenv () { unset $1; }
Then "setenv" works for bash for at least some things, like setting DISPLAY.
Trolls lurk everywhere. Mod them down.
I personally use tcsh, but I write my scripts for bourne. The bash scripting argument is weak if you ask me, simply because it isn't as portable as sh, and its extensions offer very little (if anything) beyond bourne for scripting. Whenever I run into a "bash script" I port it to bourne... immediately.
This seems more like a popularity move than anything else the way I see it...
--Tim