[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] bash to csh converter?
From: |
Mun |
Subject: |
Re: [Help-bash] bash to csh converter? |
Date: |
Tue, 22 Mar 2016 22:24:02 -0700 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
Hi Bob,
On Tue, Mar 22, 2016 at 08:09 PM PDT, Bob Proulx wrote:
BP> Mun wrote:
BP> > I'm wondering if the issue with this script stems from that fact that it
BP> > must be sourced (in order to update the user's environment variables)?
BP> > We have other bash scripts which do not require to be sourced and those
BP> > run correctly when launched from a csh environment.
BP>
BP> Yes. That you are trying to source these scripts is a critical piece
BP> of information. In the sense that the rest of us are talking about
BP> those are not really standalone scripts, which is why we were talking
BP> about the #! lines.
BP>
BP> Sourced scripts ignore #! lines because those are simply comments to
BP> the shell reading it at that point. Source scripts are explicitly
BP> interpreted by the current shell, as it was instructed to do.
BP> Therefore the syntax must of course be compatible syntax with the
BP> current shell.
Ah, okay. That makes sense.
BP> The bash documentation says this (the same is true for csh and other
BP> shells too):
BP>
BP> source filename [arguments]
BP> Read and execute commands from filename in the current
shell
BP> environment ...
BP>
BP> > GW> If this is what you're experiencing, the fix is to put the correct
BP> > GW> shebang on your script. Every time.
BP> >
BP> > I wish it were that easy, but that is not my problem.
BP>
BP> Agreed. But it is only with this email that we have arrived at what
BP> was actually the problem.
Sorry about that. This thread kind of took a turn from what I had originally
intended and thus I failed to provide essential details.
BP> > Since it seems that a script or program is not available to convert our
BP> > bash scripts to csh, I will look into why this bash script that must be
BP> > sourced is behaving badly when executed from a csh environment.
BP>
BP> AFAIK there isn't any automated conversion available. I don't think
BP> it is possible in the completely 100% case. Maybe possible in a
BP> restricted subset of typical script syntax. Probably.
BP>
BP> I have been in similar situations as you are now in needing to set
BP> environment variables from a different shell syntax of csh and ksh.
BP> Here is what I did in that case. This is off the top of my head. I
BP> will try testing it later and updating if I miss type but the concept
BP> is valid regardless.
BP>
BP> exec tcsh -c 'source environ.csh; exec bash'
BP>
BP> First I exec csh to replace the current shell with tcsh. Then in that
BP> shell it is instructed to source the environment setting script. That
BP> script sets and exports to the environment all of the environment
BP> variables as needed by the task specific command environment.
BP> (Corporate CAD/EDA tools by any chance?) Then after having sourced
Yes, EDA :)
BP> that and exported those environment variables then I exec bash again
BP> to replace the current csh with bash. The exported environment
BP> variables are now in my current bash command line environment. I can
BP> then proceed to run the CAD tools as needed.
BP>
BP> Make sense? Try that technique and see how it works for you. It's a
BP> hack but a useful one considering the other constraints. This is for
BP> the command line. Could be set up as a bash alias. But if you try to
BP> do this automatically at login time from the bash .profile or .bashrc
BP> it will need somewhat different special handling.
Yes, your technique does make sense. I'll try that out. Thanks for the
detailed explanation.
Best regards,
--
Mun
- [Help-bash] bash to csh converter?, Mun, 2016/03/18
- Re: [Help-bash] bash to csh converter?, Bob Proulx, 2016/03/18
- Re: [Help-bash] bash to csh converter?, Mun, 2016/03/19
- Re: [Help-bash] bash to csh converter?, Steven Ford, 2016/03/19
- Re: [Help-bash] bash to csh converter?, Mun, 2016/03/21
- Re: [Help-bash] bash to csh converter?, Greg Wooledge, 2016/03/21
- Re: [Help-bash] bash to csh converter?, Mun, 2016/03/22
- Re: [Help-bash] bash to csh converter?, Bob Proulx, 2016/03/22
- Re: [Help-bash] bash to csh converter?,
Mun <=
- Re: [Help-bash] bash to csh converter?, Greg Wooledge, 2016/03/23
- Re: [Help-bash] bash to csh converter?, Mun, 2016/03/23
- Re: [Help-bash] bash to csh converter?, Bob Proulx, 2016/03/21
- Re: [Help-bash] bash to csh converter?, Bob Proulx, 2016/03/19