help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] bash to csh converter?


From: Bob Proulx
Subject: Re: [Help-bash] bash to csh converter?
Date: Tue, 22 Mar 2016 21:09:05 -0600
User-agent: Mutt/1.5.24 (2015-08-30)

Mun wrote:
> I'm wondering if the issue with this script stems from that fact that it
> must be sourced (in order to update the user's environment variables)?
> We have other bash scripts which do not require to be sourced and those
> run correctly when launched from a csh environment.

Yes.  That you are trying to source these scripts is a critical piece
of information.  In the sense that the rest of us are talking about
those are not really standalone scripts, which is why we were talking
about the #! lines.

Sourced scripts ignore #! lines because those are simply comments to
the shell reading it at that point.  Source scripts are explicitly
interpreted by the current shell, as it was instructed to do.
Therefore the syntax must of course be compatible syntax with the
current shell.

The bash documentation says this (the same is true for csh and other
shells too):

       source filename [arguments]
              Read and execute commands from filename  in  the  current  shell
              environment ...

> GW> If this is what you're experiencing, the fix is to put the correct
> GW> shebang on your script.  Every time.
> 
> I wish it were that easy, but that is not my problem.

Agreed.  But it is only with this email that we have arrived at what
was actually the problem.

> Since it seems that a script or program is not available to convert our
> bash scripts to csh, I will look into why this bash script that must be
> sourced is behaving badly when executed from a csh environment.

AFAIK there isn't any automated conversion available.  I don't think
it is possible in the completely 100% case.  Maybe possible in a
restricted subset of typical script syntax.  Probably.

I have been in similar situations as you are now in needing to set
environment variables from a different shell syntax of csh and ksh.
Here is what I did in that case.  This is off the top of my head.  I
will try testing it later and updating if I miss type but the concept
is valid regardless.

  exec tcsh -c 'source environ.csh; exec bash'

First I exec csh to replace the current shell with tcsh.  Then in that
shell it is instructed to source the environment setting script.  That
script sets and exports to the environment all of the environment
variables as needed by the task specific command environment.
(Corporate CAD/EDA tools by any chance?)  Then after having sourced
that and exported those environment variables then I exec bash again
to replace the current csh with bash.  The exported environment
variables are now in my current bash command line environment.  I can
then proceed to run the CAD tools as needed.

Make sense?  Try that technique and see how it works for you.  It's a
hack but a useful one considering the other constraints.  This is for
the command line.  Could be set up as a bash alias.  But if you try to
do this automatically at login time from the bash .profile or .bashrc
it will need somewhat different special handling.

> Thanks for the insights everyone.

Happy for the discussion.

Bob



reply via email to

[Prev in Thread] Current Thread [Next in Thread]