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: Mun
Subject: Re: [Help-bash] bash to csh converter?
Date: Tue, 22 Mar 2016 15:36:25 -0700
User-agent: Mutt/1.5.21 (2010-09-15)

Hi Greg,

On Mon, Mar 21, 2016 at 10:17 AM PDT, Greg Wooledge wrote:
GW> On Mon, Mar 21, 2016 at 10:01:32AM -0700, Mun wrote:
GW> > For example, the first thing I hit was that when I run the
GW> > script under csh, I get the following error:
GW> > 
GW> > File name too long.
GW> > if: Expression Syntax.
GW> 
GW> You should not be running a script "under csh" or "under bash" or
GW> "under perl" or "under" any interpreter other than the one for which it
GW> was written.  That makes as much sense as trying to compile a FORTRAN
GW> program with a C compiler.
GW> 
GW> The first line of every script should be a shebang telling the kernel
GW> which interpreter to use when executing the script.

Agreed.  And all of my scripts do start with the shebang line; including
the trouble-maker I'm currently dealing with (which is actually just the
first of many).

GW> Scripts with a shebang are executed just like ordinary programs, and
GW> it doesn't matter which shell you're in.

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.

GW> imadev:~$ head -n 1 /usr/bin/which
GW> #! /usr/bin/csh
GW> imadev:~$ ps -fp $$
GW>      UID   PID  PPID  C    STIME TTY       TIME COMMAND
GW>  wooledg 26571 26570  1  Feb 15  ttypa     0:01 bash-4.4
GW> imadev:~$ /usr/bin/which ls
GW> /usr/bin/ls
GW> 
GW> which(1) is a csh script on this machine, but it runs fine when my
GW> interactive shell is bash.  Likewise, if I change my interactive shell
GW> to tcsh, I can run sh/ksh/bash scripts with no problems.
GW> 
GW> Now, you might run into a problem if you fail to put a shebang on the
GW> script.  Text files with no shebang fail at the kernel level with an
GW> "exec format error".  When that happens, the shell that tried to run
GW> the script might decide to try again, using itself as the interpreter.
GW> 
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.

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.

Thanks for the insights everyone.

Regards,

-- 
Mun



reply via email to

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