Slashdot Mirror


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?"

9 of 89 comments (clear)

  1. Re:No change forced... by notfancy · · Score: 5, Informative

    >> You can always edit /etc/passwd

    > Why not use the command designed for this sort of thing, "chsh"?

    Since chsh updates /etc/passwd, and since Mac OS X doesn't generally rely on /etc files but on the NetInfo database, neither would work. You have to use the niutil command or the NetInfo Manager application (it lives in Applications/Utilities).
  2. Shell functions by Anonymous+Cowdog · · Score: 5, Informative

    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).

    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 .bashrc):

    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

  3. FAQs by citmanual · · Score: 2, Informative

    Google "bash tcsh differences" yields:

    "UNIX shell diferences and how to change your shell."

  4. script mod by gmhowell · · Score: 4, Informative

    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
  5. Re:bash is nice, tcsh is nicer... by neden · · Score: 2, Informative

    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.


    Huh? configure scripts should have

    #! /bin/sh

    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.

  6. Re:No change forced... by PeekabooCaribou · · Score: 2, Informative
    % sudo niutil -createprop / /users/$USER shell /bin/bash

    As you mentioned, chsh will not work.

    --
    "I'll say it again for the logic-impaired." -- Larry Wall.
  7. Setting variables by PeekabooCaribou · · Score: 3, Informative
    I'm not a huge tcsh user, but the most immediate difference is the way variables are set in the two shells. Here's tcsh:

    % setenv PATH ${PATH}:/usr/local/bin
    % echo $PATH
    /bin:/usr/bin:/usr/local/bin
    % unsetenv PATH

    And bash:

    $ export PATH=$PATH:/usr/local/bin
    $ echo $PATH
    /bin:/usr/bin:/usr/local/bin
    $ unset PATH

    There are other differences, of course, but it's a start.

    --
    "I'll say it again for the logic-impaired." -- Larry Wall.
  8. Flashback by AT · · Score: 4, Informative

    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

  9. My brief summary by chad_r · · 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:

    • ability to redirect stdout and stderr separately:
      ( cmd > file.out 2> file.err)
    • nested command substitution, when using $() instead of ``:
      ls -aFl $(find $(locate xterm) -type f -perm -a+x)
    • More straightforward syntax, with the possibility of fitting while/if/case blocks on a single command line (especially useful for command substitutions)
      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.