Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

conversion of csh scripts to bash

1,529 views
Skip to first unread message

Giulia Paramour

unread,
Nov 30, 2003, 12:47:54 PM11/30/03
to

Hi,

I have in my possession about 300 csh scripts written by me over the
course of the last 10 years. Occasionally I have to give these to other
people. When I do, any smart little bastard who's ever been to a 1 week
computing course then says "Ah, but my teacher said that anyone who
persists in using csh/tcsh instead of bash is clearly an idiot.".
Result : due to constant repetition, my reputation goes down the tube
and various annoying little bastards get their heads kicked in. Tears
all round.

I recognize that bash is the superior shell, but like many people, I was
first exposed to csh 12 years ago because that's what everyone in my
university department used, and I never got round to changing. So here's
what I'm going to do to defend my csh behaviour : nothing. I'm going to
cravenly give up and learn how to use bash before I get too old to
change. Then the snivelling little rats will learn who's in charge.

I don't want to convert all my 300 csh scripts by hand though (some of
them run to several thousand lines!). Is there some sort of converter
out there that will do a basic csh-->bash conversion on a script? Even
if it only does it badly so I can correct it that would be fine. I've
done a web search, but could only find tools to convert your tcsh
aliases and interactive environment to bash equivalents..

Thanks
G.

--
====================================
Giulia Paramour
giulia_paramour(at)postmaster.co.uk
====================================

Stephane CHAZELAS

unread,
Nov 30, 2003, 2:15:35 PM11/30/03
to
2003-11-30, 17:47(+00), Giulia Paramour:
[...]

> I recognize that bash is the superior shell, but like many people, I was
> first exposed to csh 12 years ago because that's what everyone in my
> university department used
[...]

At that time, csh was a superior choice for interactive use and
at least was not proprietary software (contrary to sh or ksh).

Note that shell programming sucks in general, csh programming
sucks more than bash programming, but bash is far from being
perfect. It's now popular because of GNU/Linux popularity but,
as a (mostly) ksh clone it suffers from the same design errors
and has an awkward and inconsistent syntax.

Moreover, it's not standard (you're more likely to find perl
installed on a random Unix system than bash).

I'd suggest to use a real programming language such as perl or
python, especially for complex scripts.

I would certainly not write bash specific scripts, but instead,
if I had to write /shell/ scripts, scripts with a POSIX
conformant syntax, that is scripts that would work correctly
when interpreted by any POSIX conformant shell (such as bash).
This would reduce the porting overhead and you could answer to
the "little bastards" with the magic word "standard". See the
Single Unix Specification for details
(http://www.opengroup.org/onlinepubs/007904975/utilities/contents.html)

Googling for "csh2sh" or "cshtosh" (www and groups), you'll find
utilities (often perl scripts) to help converting csh scripts to
sh. However note that the resulting sh scripts could be Bourne
scripts and not POSIX scripts. Anyway, you'll have to edit the
result because there's generally not a simple mapping from csh
to sh syntax.

--
Stéphane ["Stephane.Chazelas" at "free.fr"]

Kenny McCormack

unread,
Nov 30, 2003, 3:17:12 PM11/30/03
to
In article <slrnbskgen.42.s...@spam.is.invalid>,
Stephane CHAZELAS <this.a...@is.invalid> wrote:
...

>Note that shell programming sucks in general, csh programming
>sucks more than bash programming, but bash is far from being
>perfect. It's now popular because of GNU/Linux popularity but,
>as a (mostly) ksh clone it suffers from the same design errors
>and has an awkward and inconsistent syntax.

All programming sucks. All script languages (yes, this includes
perl/pythion/etc) suffer from the same basic limitation - which is that
they aren't real programming languages - they are approximations, based on
the assumption that most users don't need full power and will gladly trade
that away for ease-of-use. They are also, by their very nature, ephemeral.
That is, they won't last as paradigms (Think: flavor-of-the-month).
And we won't even go into "Microsoft" here.

That said, I cringe every time I hear about someone having written
"thousands of lines of code" in *any* scripting language.

Harry

unread,
Dec 1, 2003, 4:15:53 PM12/1/03
to
Giulia Paramour wrote...

>I have in my possession about 300 csh scripts written by me over the
>course of the last 10 years. Occasionally I have to give these to other
>people. When I do, any smart little bastard who's ever been to a 1 week
>computing course then says "Ah, but my teacher said that anyone who
>persists in using csh/tcsh instead of bash is clearly an idiot.".
>Result : due to constant repetition, my reputation goes down the tube
>and various annoying little bastards get their heads kicked in. Tears
>all round.

You don't need to give them source codes, do you?
You can "compile" your shell script using "shell compiler."
Search for shc-3.2.tgz using FTP Search Engine (http://www.alltheweb.com/.)

>I don't want to convert all my 300 csh scripts by hand though (some of
>them run to several thousand lines!). Is there some sort of converter
>out there that will do a basic csh-->bash conversion on a script? Even
>if it only does it badly so I can correct it that would be fine. I've
>done a web search, but could only find tools to convert your tcsh
>aliases and interactive environment to bash equivalents..

Even if you have found such a tool. Don't expect the converted
scripts will run for the first time without extensive editing & debugging.


Giulia Paramour

unread,
Dec 1, 2003, 6:20:01 PM12/1/03
to
Harry wrote:
> Giulia Paramour wrote...

>
> You don't need to give them source codes, do you?
> You can "compile" your shell script using "shell compiler."
> Search for shc-3.2.tgz using FTP Search Engine (http://www.alltheweb.com/.)
>

Sadly yes, the source codes do get distributed. Also, my code
distribution (lots of fortran90 - ooh, that's unfashionable too - run by
shell scripts) needs to be portable across about 15 different
architectures (i.e. various obscure supercomputers as well as Linux
boxes) and lots of individual machines around the world with differing
and possibly idiosyncratic setups. I'm not sure how portable shell
compilers are and whether they're available on all machines (I suspect not).

>
> Even if you have found such a tool. Don't expect the converted
> scripts will run for the first time without extensive editing & debugging.
>

No - I'm aware of that. But there is obviously such a lot of stuff like
converting 'set a = 1' to 'a=1' which could be automated that I just
wondered if anyone had ever bothered to do so?

Giulia Paramour

unread,
Dec 1, 2003, 6:28:18 PM12/1/03
to
Kenny McCormack wrote:
> In article <slrnbskgen.42.s...@spam.is.invalid>,
> Stephane CHAZELAS <this.a...@is.invalid> wrote:
> ...

>

> That said, I cringe every time I hear about someone having written
> "thousands of lines of code" in *any* scripting language.

Yeah I know.

I guess I need to a lot of complicated things. The only other langauage
I knew when I originally needed to do them was fortran 90, which
obviously isn't suitable for the kind of things that shell scripts do.

Even though I say so myself, the scripts (csh!) do work very well. One
can simply type 'go' and an entire research project gets done. Nice
trick if you can do it. Like I said I'm more worried about being
fashionable than anything - I guess I'm just sensitive. Clearly I am
also aware that the same scripts written in bash would probably be a
little shorter and wouldn't have to be quite so many thousand lines.

I don't know python or perl etc. and I have too many zillion things to
do to find time to learn them.

Paddy McCarthy

unread,
Dec 1, 2003, 8:54:22 PM12/1/03
to
Giulia Paramour <giulia_...@postmaster.co.uk> wrote in message news:<bqdagh$8r6$1...@pegasus.csx.cam.ac.uk>...

If your sxripts work then I would not change them except for maybe
adding a covering note.
Meanwhile you might research what scripting languages are
available/can be made available on all the (15 was it?) Unix systems
you must support.
(If it comes down to a choice between Perl and Python then I'd choose
Python).
Learn the scripting language then when a script needs modifying then
think instead of re-coding it in the scripting language.

If you want to investigate an alternate to your fortran code maybe
http://www.scipy.org/ will be of help. The following distribution of
Python has a popular scientific packages already included:
http://www.enthought.com/python/

Stephane CHAZELAS

unread,
Dec 2, 2003, 5:28:31 AM12/2/03
to
2003-12-1, 17:54(-08), Paddy McCarthy:
[...]

> If you want to investigate an alternate to your fortran code maybe
> http://www.scipy.org/ will be of help. The following distribution of
> Python has a popular scientific packages already included:
> http://www.enthought.com/python/

See also octave (http://www.octave.org/).

Rich

unread,
Dec 2, 2003, 10:11:08 AM12/2/03
to

Giulia Paramour replied:


>
> Hi,
>
> I have in my possession about 300 csh scripts written by me over the
> course of the last 10 years. Occasionally I have to give these to other
> people. When I do, any smart little bastard who's ever been to a 1 week
> computing course then says "Ah, but my teacher said that anyone who
> persists in using csh/tcsh instead of bash is clearly an idiot.".

I understand the issues with csh, it's still the original buggy shell.
But my understanding is that tcsh rather fixed the bugs and the shortcomings
of csh (WRT scripting). I don't see lumping them together. What's the deal?

Rich

Giulia Paramour

unread,
Dec 2, 2003, 4:40:36 PM12/2/03
to
Paddy McCarthy wrote:

> If your sxripts work then I would not change them except for maybe
> adding a covering note.

Well, as it seems that there is no tool which would help me to convert
them, I think it would be too big a job to recode them by hand. Maybe it
should be as you say.

> Meanwhile you might research what scripting languages are
> available/can be made available on all the (15 was it?) Unix systems
> you must support.
> (If it comes down to a choice between Perl and Python then I'd choose
> Python).
> Learn the scripting language then when a script needs modifying then
> think instead of re-coding it in the scripting language.

I'll consider it. Finding the time to learn is always a problem though.

> If you want to investigate an alternate to your fortran code maybe
> http://www.scipy.org/ will be of help. The following distribution of
> Python has a popular scientific packages already included:
> http://www.enthought.com/python/

Ah, no. I certainly don't want to change the fortran90 (all 100,000+
lines of it!). It's a work of computational genius and if any of the
little bastards try to criticise that, they'll get a stake through their
heart. I am not aware that fortran has any serious rival when it comes
to high level numerical computation where speed is a critical issue.

Stephane CHAZELAS

unread,
Dec 2, 2003, 5:18:09 PM12/2/03
to
2003-12-02, 21:40(+00), Giulia Paramour:

> Paddy McCarthy wrote:
>
>> If your sxripts work then I would not change them except for maybe
>> adding a covering note.
>
> Well, as it seems that there is no tool which would help me to convert
> them
[...]

Yes, there is, as I said:

Get csh2sh-rca.pl and fmt.script from:
http://perso-info.enst-bretagne.fr/~aubert/perl/

That's not perfect, but it should perform a great part of the
job.

Giulia Paramour

unread,
Dec 2, 2003, 5:55:12 PM12/2/03
to
Stephane CHAZELAS wrote:

>
> Yes, there is, as I said:
>
> Get csh2sh-rca.pl and fmt.script from:
> http://perso-info.enst-bretagne.fr/~aubert/perl/
>
> That's not perfect, but it should perform a great part of the
> job.
>


Oh great. Merci Stephane. I'll check it out.

Travis N. Vaught

unread,
Dec 10, 2003, 7:17:52 AM12/10/03
to
Giulia Paramour <giulia_...@postmaster.co.uk> wrote in message news:<bqj0sp$h5i$1...@pegasus.csx.cam.ac.uk>...
> Paddy McCarthy wrote:
>
<snip>

>
> > If you want to investigate an alternate to your fortran code maybe
> > http://www.scipy.org/ will be of help. The following distribution of
> > Python has a popular scientific packages already included:
> > http://www.enthought.com/python/
>
> Ah, no. I certainly don't want to change the fortran90 (all 100,000+
> lines of it!). It's a work of computational genius and if any of the
> little bastards try to criticise that, they'll get a stake through their
> heart. I am not aware that fortran has any serious rival when it comes
> to high level numerical computation where speed is a critical issue.
>
> G.


We agree. That's why scipy is mostly wrapped fortran code (cephes
libraries and others). The big win is that Python can be used as a
framework and adding components simply requires wrapping them in
python (or writing them in Python if the speed is tolerable). You are
then able to avoid the n^2 interfaces you have to build if you wanted
various components to interface individually.

As it is, however, your code may be too monolithic to consider
wrapping (globals usage?), and, perhaps you'd be better off calling it
externally with scripts. Just a thought.

Travis

0 new messages