> You would also need to change the top line of the file so 
> that it was something like "#!/bin/bash -f", though I would 
> be more inclined to use a proper traditional Bourne shell for 
> this and use "#!/bin/sh -f" and use "set"s and "export"s throughout.

That's not actually necessary for a 'sourced' script because 'source'
reads it as a text file, not as an executable script, i.e. all you are
doing is temporarily switching input for the *current* shell from the
terminal to the file and back again.  So the first line, whatever it is,
if it begins with '#' it will be treated as a comment (that's why the
'#' is put there!).  In contrast, *running* a shell script starts a
*new* (child) shell (which need not be the same shell as the parent
shell).  If you start it like so: 'shell script_name' the shell
specified on the command line is used and any shell specification inside
the script is ignored; whereas if you start it like so: 'script_name'
(in which case it must be made executable first otherwise you will get
'permission denied'), then the shell specified by the first line
'#!shell' is used (if the first line is not in this format it uses
/bin/sh and the line is treated as a normal shell command).  For a
script which is intended to set up the environment for other programs
(e.g. CCP4) it's essential to source the file so that the commands in
the file modify the environment of the current shell from which you will
launch the programs.  If you run it in a child shell the environment set
up for the child process is *not* passed back to the parent shell, so it
will have absolutely no effect.

I often see people *running* programs (i.e. not just setting up the
environment) by sourcing a script, i.e. the script contains commands for
running programs: I always think that's a dangerous thing to do because
anything in the file which changes the environment will change the
environment for the terminal shell you are using, with unpredictable
consequences for things you type in later.  If I do that accidentally I
always immediately terminate the terminal shell and start a new one so
that the shell is in a known state, just to be on the safe side.  It's
always safer to *run* programs with a shell script using 'shell
script_name' or 'script_name' so then the script is completely isolated
from the terminal shell.
 
> If you really want to run the script, I would use tcsh or 
> csh, rather than trying to modify it so that it is a bash script.

That's all very well but people use other shells for their terminal
sessions for other reasons (e.g. csh/tcsh isn't guaranteed to be
portable, or the user may already have setup scripts for their current
shell which they don't want to rewrite).  As indicated above the
commands used in a 'sourced' script must correspond to the terminal
shell, since it is that environment you want to modify: any shell
specification inside the script is ignored, e.g. if you want to use bash
for your terminal shell (many people do!) then the sourced file *must*
contain bash commands, there's no way around it (this is why CCP4
supplies versions of the setup script for both sh and csh).

Cheers

-- Ian


Disclaimer
This communication is confidential and may contain privileged information 
intended solely for the named addressee(s). It may not be used or disclosed 
except for the purpose for which it has been sent. If you are not the intended 
recipient you must not review, use, disclose, copy, distribute or take any 
action in reliance upon it. If you have received this communication in error, 
please notify Astex Therapeutics Ltd by emailing [EMAIL PROTECTED] and destroy 
all copies of the message and any attached documents. 
Astex Therapeutics Ltd monitors, controls and protects all its messaging 
traffic in compliance with its corporate email policy. The Company accepts no 
liability or responsibility for any onward transmission or use of emails and 
attachments having left the Astex Therapeutics domain.  Unless expressly 
stated, opinions in this message are those of the individual sender and not of 
Astex Therapeutics Ltd. The recipient should check this email and any 
attachments for the presence of computer viruses. Astex Therapeutics Ltd 
accepts no liability for damage caused by any virus transmitted by this email. 
E-mail is susceptible to data corruption, interception, unauthorized amendment, 
and tampering, Astex Therapeutics Ltd only send and receive e-mails on the 
basis that the Company is not liable for any such alteration or any 
consequences thereof.
Astex Therapeutics Ltd., Registered in England at 436 Cambridge Science Park, 
Cambridge CB4 0QA under number 3751674

Reply via email to