What's the point of #! in a sourced file?

What's the point of #! in a sourced file?

Post by wayne t. wats » Thu, 12 Jun 1997 04:00:00



What's the point of including something like:

#!/bin/csh
set x=2
echo $x
...
in a file that will always be sourced?  I am working
on a Solaris platform?  Does this imply the sourced
code is written in the c shell, so don't try to source
it with the Korn shell?
--
    Wayne T. Watson  |                              |     /  *              
   The Software Hill |  Consulting in C, UNIX, C++  |    /              .    *
   Mountain View, CA |  Motif, X-Windows, Graphics  |   //            *
    (415) 969-4233   |    Statistics, Science,      |  o         *      .

        "Progress might have been all right once but it has gone on
        far too long."  Ogden Nash

 
 
 

What's the point of #! in a sourced file?

Post by Barry Margoli » Thu, 12 Jun 1997 04:00:00


If the file is sourced, the #! line has no effect.  It's a comment line,
like any other line beginning with #.  Consider it to be a type of
self-documentation.  The interpreter that sources the file won't produce an
error as a result of the line not matching the interpreter name (on the
other hand, you'll probably get errors due to the shell not recognizing
some of the syntax).

--

BBN Corporation, Cambridge, MA
Support the anti-spam movement; see <http://www.cauce.org/>

 
 
 

What's the point of #! in a sourced file?

Post by Nick Wag » Fri, 13 Jun 1997 04:00:00



> What's the point of including something like:

> #!/bin/csh
> set x=2
> echo $x
> ...
> in a file that will always be sourced?

For a file which is intended to be sourced rather than shelled I usually
start it with:

#! /bin/echo "This file should be sourced"

That way, if I inadvertently attempt to execute it, I get a message
reminding me of the fact, without attempting to execute the rest.

--

Senior Software Engineer                  Science Park, Milton Rd,
Tel: +44(0)1223 420414 (ext 213)          Cambridge, CB4 4FY, UK.
Fax: +44(0)1223 420044                    http://www.lsl.co.uk/

 
 
 

What's the point of #! in a sourced file?

Post by Francois Deryc » Fri, 13 Jun 1997 04:00:00




> > What's the point of including something like:

> > #!/bin/csh
> > set x=2
> > echo $x
> > ...
> > in a file that will always be sourced?

> For a file which is intended to be sourced rather than shelled I usually
> start it with:

> #! /bin/echo "This file should be sourced"

> That way, if I inadvertently attempt to execute it, I get a message
> reminding me of the fact, without attempting to execute the rest.

Is it possible to set the first line in order to automatically source
the file if one attempt to execute it ?

Something like

        #!source

But I don't think it will work has source is a build-in function.

Any idea ?

Slad.
--

        (o o)                  http://www.tele.ucl.ac.be/PEOPLE/fd.html
-----oOO-(_)-OOo-------------------------------------------------------
Ir. Fran?ois Deryck - Research Assistant       Phone : +32 10 47 80 71
UCL - Universit Catholique de Louvain                 +32 10 47 23 00
Communications and Remote Sensing Laboratory    Fax   : +32 10 47 20 89
-----------------------------------------------------------------------

 
 
 

What's the point of #! in a sourced file?

Post by Nick Wag » Sat, 14 Jun 1997 04:00:00



> Is it possible to set the first line in order to automatically source
> the file if one attempt to execute it ?

> Something like

>         #!source

No. By the time that the line is executed you will have already started
up a new shell which is not what you want, otherwise you would not be
using source at all.

The occasions when you need to use source should be rare. Perhaps you
have an initialisation script for setting environment and shell
variables. In this case I would set an alias for sourcing the file(s)
that you want to load.

For more unusual applications you might want to investigate using eval
but I would still use an alias wrapper.
--

Senior Software Engineer                  Science Park, Milton Rd,
Tel: +44(0)1223 420414 (ext 213)          Cambridge, CB4 4FY, UK.
Fax: +44(0)1223 420044                    http://www.lsl.co.uk/

 
 
 

What's the point of #! in a sourced file?

Post by Bill Tott » Mon, 16 Jun 1997 04:00:00




 <...>

Quote:>Is it possible to set the first line in order to automatically source
>the file if one attempt to execute it ?

>Something like

>    #!source

>But I don't think it will work has source is a build-in function.

 <...>

  You are right, it will not work, but not for the reason you might think.
By the time the system is ready to start reading the file to determine
how to execute it, your shell has already forked off a new, child, process
for it. So, you cannot effectively source because the process cannot modify
the environment of the parent.

  This type of thing may be possible in some kind of brain-dead OS which
has a "spawn" instruction instead of the safer, more elegant, "fork/exec"
combo. But, I would not know, since I do not use those kinds of OS's unless
I have to. And, I certainly do not program in them.

--
Totten, William David (Bill)         Computer and Information Science Major

http://pobox.com/~totten/               Friends don't let friends use emacs

 
 
 

1. tunnel point to point vs physical point to point

If you have 2 systems on a point to point link you would address them
by a /30 block? When creating 'gre' tunnel you can use /32 for example
ip addr add 1.0.0.1 peer 1.0.0.2 dev mydev.

why can't /32 of arbitray addressing be used on a point to point
between 2 systems?

2. O(1) scheduler, 2.4.17-A1, 2.5.2-pre7-A1.

3. What's 'side effects' of Ksh built-ins?

4. DHCP License Renewal

5. Point RH 8 'packages' applet to ISO file

6. network general problem with linux-2.4.5

7. Can ISP detect when dial-ins are 'overloaded' ?

8. drivers

9. how do 'plug-ins' work?

10. Can ISP detect when dial-ins are 'overloaded' ?

11. Point-to-Point-to-Point-to-Point ad nauseum

12. Point-to-Point-to-Point

13. Any C 'ini' file writing/reading source for Linux ?