Switching from tcsh to bash? 89
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?"
big deal... (Score:4, Insightful)
Really, it's no big deal. They are both fine shells. Tcsh is rotten for programming but that doesn't affect most people.
Re:big deal... (Score:2)
I've used tcsh forever (well, I used sh and csh first, but...)
I like tcsh as my interactive shell. Honestly, I can get bash to ack exactly the same as tcsh, except that I don't know how to do reverse-video in the prompt. But I still like tcsh. I'm used to it.
If I need to do actual scripting, I use perl. Or ksh, because all the Solaris boxes at work have ksh, but not all of them have bash and/or tcsh (new ones do, but you can't rely on that).
Re:big deal... (Score:2)
PS1="normal\[\033[1;7m\]inverse\033[1;0m\]"
Re:big deal... (Score:2)
*waits for lameness filter to time out... doot dee doot...*
Re:big deal... (Score:1)
My bash prompt is currently:
PS1='\[\e]0;\l \w\007\]\n($?) \t \[\e[36m\]\l \[\e[32m\]\u@\h \[\e[33m\]\w\[\e[0m\]\n$ '
The "ESC]0;foo\007" bit sets the rxvt terminal title to the current tty and path. $
Re:big deal... (Score:2)
Re:big deal... #!/bin/sh - ????? (Score:1)
#!/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
Bash with Fink. (Score:2)
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.
Bash without Fink (Score:2)
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
No change forced... (Score:2)
Re:No change forced... (Score:1)
Why not use the command designed for this sort of thing, "chsh"?
Re:No change forced... (Score:5, Informative)
>> You can always edit /etc/passwd
> Why not use the command designed for this sort of thing, "chsh"?
Since chsh updatesRe:No change forced... (Score:3, Informative)
As you mentioned, chsh will not work.
Re:No change forced... (Score:2, Interesting)
Never cared to find out what that lookupd-process is doing?
There's another way you can make it work....
You can make some nidump dump something into
-K
Re:No change forced... (Score:2)
Re:No change forced... (Score:2)
Don't do this, it breaks sftp (Score:2)
Re:Don't do this, it breaks sftp (Score:1)
Re:Don't do this, it breaks sftp (Score:2)
Hehe, me too, and when I don't do that I use rsync over ssh like this:
So, how do we all adapt? (Score:2)
Put "set editing-mode vi" into your
Easy (Score:2)
~/.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]$ '
Re:Easy (Score:1)
Re:Easy (Score:2)
it displays a blue line in background when the screen scroll and it's easy to spot where you left sometimes (when you have 1000+ lines in your term buffer)
Um, different user target (Score:4, Insightful)
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
Shell functions (Score:5, Informative)
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
Re:Shell functions (Score:2)
Out of curiosity, how would that loop be done in tcsh? I generally prefer tcsh as my interactive shell (the spell checker embedded in the tab-completion saves me from typos all the time), but if I want to do anything as complex as a loop construct, I always just drop into a bash shell to do it.
I think bash is the better shell for s
Re:Shell functions (Score:1)
-Ster
Re:Shell functions (Score:1)
>Out of curiosity, how would that loop be done in tcsh?
I don't know how you would do it as a one-liner. That's one of the reasons I prefer bash -- after doing a for loop, I can just Ctrl-P back to it if I need to do it again, or do it again with edits.
In tcsh, you do:
> foreach n (1 2 3)
foreach? echo $n
foreach? end
But this is not on one line. So then if you do Ctrl-P to get back the foreach line, that's all you get -- the first line. You may have had some complic
Re:Shell functions (Score:1)
<a href="http://www.fictive.com/t/tdb/shell/loop/">h
(i would have posted it here, but the aliases employ a few iso8859-1 characters which didn't make it through
Re:Shell functions (Score:1)
Re:Shell functions (Score:1)
most relevantly for me, the ability to recall and re-execute such a command-line for loop using 'up-arrow' in bash
Also the ability to pipe the output from whole sections of code within ( ) through a subsequent pipeline.
FAQs (Score:2, Informative)
"UNIX shell diferences and how to change your shell."
FAQs (Score:1)
"UNIX shell differences and how to change your shell"
http://www.faqs.org/faqs/unix-faq/shell/s
Newer Linux Trends (Score:2)
Google is your friend.
Re:Newer Linux Trends (Score:1)
Of course, the fact that bash will gladly accept its extensions when running in POSIX mode only worsens the issue. If you're going to write a bash script, at least have the courtesy to designate it with "#!/usr/bin
script mod (Score:4, Informative)
#!/bin/tcsh
Should appear on line one of the script.
Even better script mod (Score:2)
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 i
Re:Even better script mod (Score:1)
Re:Even better script mod (Score:2)
If I'm remembering POSIX correctly, when the kernel goes to exec an interpreted file that doesn't have a #! at the beginning, it always uses
So the article post is completely moronic; the currently running shell has no effect at all on an executed script.
Re:Even better script mod (Score:2)
Exactly, and if you are using anything other than sh, you know to do the who # !/bin/shell thing at the top of the script
Re:Even better script mod (Score:2)
>
> 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
tcsh emulation (Score:1)
bash is nice, tcsh is nicer... (Score:1)
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 n
Re:bash is nice, tcsh is nicer... (Score:2, Informative)
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.
Re:bash is nice, tcsh is nicer... (Score:1)
Boo hiss! Evil! Bad, bad, very bad, not good.
Re:bash is nice, tcsh is nicer... (Score:2)
I grew up on tcsh, and csh before it (IIRC, csh was the default login shell in SunOS 5.0). Darnit, I like tcsh. Aliases work like they ought to, and setting shell variables is straightforward and intuitive. I think bash is just a bad shell dream, and replace it as my login shell everywhere it shows up.YMMV, but I get 100 mpg out of tcsh, where I only get 60 mpg out of bash.
Re:bash is nice, tcsh is nicer... (Score:2)
Re:bash is nice, tcsh is nicer... (Score:2)
Top five reasons to switch to bash (Score:2)
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.
Re:bash is nice, tcsh is nicer... (Score:2)
bind '"\M-[A":history-search-backward'
bind '"\M-[B":history-search-forward'
Re:bash is nice, tcsh is nicer... (Score:1)
> change bash to tcsh.
Same here.
> And today, I'm left contemplating whether I should
> change my default shell in Linux to tcsh.
Go for it. When I was using Slackware Linux, I used tcsh as my default shell, (I can't stand bash personally) and I never had any problems of that nature. From what I understand the bourne-dependent scripts that would take issue with this would default to bourne or bash anyway.... Defaulting root to tcsh might cau
Setting variables (Score:4, Informative)
% 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.
Re:Setting variables (Score:2)
In tcsh, you shouldn't muck with environment variable PATH, you should set shell variable 'path' instead, eg
set path=(/usr/bin
instead of
setenv PATH
bash has only variables, which, if 'export'ed, become part of the environment.
Baz
Re:Setting variables (Score:2)
bash has only variables, which, if 'export'ed, become part of the environment.
So just don't export the variables used locally in your script. Set a local path variable like you would in tcsh:
locpath="/usr/bin:/home/me/bin"
If not exported, it goes away at the end of the script.
tcsh-to-bash script (Score:2)
setenv () { export $1=$2; }
unsetenv () { unset $1; }
Then "setenv" works for bash for at least some things, like setting DISPLAY.
Flashback (Score:5, Informative)
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 [cwru.edu]
http://www.caliban.org/bash/index.shtml [caliban.org]
http://www.deadman.org/bash.html [deadman.org]
Re:Flashback (Score:1)
Any bourne-like shell is better for scripting. Way back when, sh and descendents were for scripting, while csh and descendents were for users. Without bash, that would still be true. But bash gave us all the goodness of ksh and tcsh in one package.
I still program in plain vanilla bourne shell (because it's the Right Thing(tm) to do), but my user shell is bash instead of tcsh.
Re:Flashback (Score:2)
The right thing to do if you enjoy using backticks and eval statements.
Re:Flashback (Score:1)
"\ep": history-search-backward
Here are some other nice ones that conform to my former tcshrc:
set bell-style none
set completion-ignore-case on
set show-all-if-ambiguous
Re:Flashback (Score:1)
The quirky scripting syntax aside, tcsh is a really feature-rich, mature shell. I miss it dearly in my heart of hearts.
more a niggle with OS X (Score:2, Insightful)
But why? (Score:2)
My brief summary (Score:2, Informative)
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)
setenv is the only real problem I've ever seen (Score:2)
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.
Re:setenv is the only real problem I've ever seen (Score:2)
~/.bashrc (Score:2)
why shell anyway? (Score:2)
Using Bash on Apple (Score:2)
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!
Yeah, but would anyone ever notice? (Score:2)
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 exper
Related question (Score:2)
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.
How do I get the OSX shell anyway? (Score:1)
not very consistent (Score:1)
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. Wh