Re: Portable shell scripts
On Mon, 10 Nov 2003 23:18:56 -0700,
Bob Proulx wrote:
>
> csj wrote:
> > Is there a way to write portable shell scripts. In
> > particular, I've problems with built-ins setenv (tcsh) and
> > export (bash). How do I define variables in tcsh and have
> > them usable in bash too?
>
> Your best option is "#!/bin/sh" at the top of all of your
> scripts. Then you will always have a consistent syntax. By
> your posting it sounds to me like you have not been putting a
> #! line in your scripts and have been taking "post-luck" over
> whatever shell the user is running at the moment. That will
> cause you no end of grief.
I tend to write scripts which are tcsh-compatible. So
"#!/bin/tcsh". But its somewhat a waste of effort to write one
set of scripts for bash and another for tcsh. My main problem is
handling the variables. Is there a shell-portable way to specify
variables? I write mostly convenience scripts that are generally
less than a console screen in length.
Reply to: