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: Greg Wooledge
Subject: Re: [Help-bash] bash to csh converter?
Date: Mon, 21 Mar 2016 13:17:30 -0400
User-agent: Mutt/1.4.2.3i

On Mon, Mar 21, 2016 at 10:01:32AM -0700, Mun wrote:
> For example, the first thing I hit was that when I run the
> script under csh, I get the following error:
> 
> File name too long.
> if: Expression Syntax.

You should not be running a script "under csh" or "under bash" or
"under perl" or "under" any interpreter other than the one for which it
was written.  That makes as much sense as trying to compile a FORTRAN
program with a C compiler.

The first line of every script should be a shebang telling the kernel
which interpreter to use when executing the script.

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

imadev:~$ head -n 1 /usr/bin/which
#! /usr/bin/csh
imadev:~$ ps -fp $$
     UID   PID  PPID  C    STIME TTY       TIME COMMAND
 wooledg 26571 26570  1  Feb 15  ttypa     0:01 bash-4.4
imadev:~$ /usr/bin/which ls
/usr/bin/ls

which(1) is a csh script on this machine, but it runs fine when my
interactive shell is bash.  Likewise, if I change my interactive shell
to tcsh, I can run sh/ksh/bash scripts with no problems.

Now, you might run into a problem if you fail to put a shebang on the
script.  Text files with no shebang fail at the kernel level with an
"exec format error".  When that happens, the shell that tried to run
the script might decide to try again, using itself as the interpreter.

If this is what you're experiencing, the fix is to put the correct
shebang on your script.  Every time.



reply via email to

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