I have two very distinct parts to this answer. I'll start with the slightly more technical bit, and then with more of personal thought (ok, rant).
bash shell comes with a
cshtobash script hidden away in the
examples/misc directory of its source distribution.
This will not take a
csh script and convert it into
bash, but it may possibly be useful for someone as a first step in creating a prototype
~/.profile file from an already existing
Input: Standard OpenBSD
csh initialization file.
# $OpenBSD: dot.login,v 1.6 2015/12/15 16:37:58 deraadt Exp $
# csh login file
if ( ! $?TERMCAP ) then
if ( $?XTERM_VERSION ) then
tset -IQ '-munknown:?vt220' $TERM
tset -Q '-munknown:?vt220' $TERM
stty newcrt crterase
setenv EXINIT 'set ai sm noeb'
if (-x /usr/games/fortune) /usr/games/fortune
Output: Not quite the same thing for
bash... but at least something.
# csh aliases
# csh environment variables
export EXINIT='set ai sm noeb'
# csh variables
set -o ignoreeof # ignoreeof
# special csh variables converted to bash equivalents
Yes, C-shell programming is "considered harmful". That does not mean that you can't write C-shell shell scripts that are not harmful, or not robust. It also does not mean that every single C-shell script needs to be converted to
bash. And it definitely doesn't mean that such a conversion should be done by an automatic tool! It just means it's an awkward language that has some really odd quirks, especially if you're more used to
As with any two programming languages, when one falls out of fashion to the benefit of the other, this does not mean that existing software needs to be rewritten. It also doesn't mean that proficient speakers of the out-of-fashion language should stop speaking. It just means that this may not be the language to pick up if you're looking for a modern language to do shell scripting in.
On the other hand, if you're given the task of extending or in some other way modify a
csh script, then there might be a reason to
- read the code
- understand it
- reimplement it in another language
... especially if you're not good at
As for automatic translation: Why?
If the script is working and you have the interpreter for it on your system, there is no need for translate the code. Translating the code automatically is unlikely to generate "better" code, and it very likely won't generate maintainable code, and you'd have to spend time on verifying that the translated script behaves in the same way as the original script anyway.