[plug] bash bodgy
James Devenish
devenish at guild.uwa.edu.au
Sat Jun 5 20:23:38 WST 2004
In message <40C1B6D7.80400 at westnet.com.au>
on Sat, Jun 05, 2004 at 08:04:39PM +0800, Craig Dyke wrote:
> This would be all well and good but there is a significant amount of
> scipt before this line. Will that matter? I understand what you have
> written and how it works for my small example, but wonder if it will
> translate to larger problem?
It is not commonplace practice to do this with arbitrary shell scripts.
The technique certainly has its place, and you probably wouldn't have to
go far to find a active example, but it is usually only used when it is
known to be a necessary requirement and the script is known to be safe
(compatible) and appropriate. A typical use of this technique is when a
parent shell wants to execute lines from another script that merely
contains assignments to environment variables.
Explanation: your script (the one that starts with "#!/bin/bash") is
executed as a child process ("subshell") of your current shell (a.k.a.
parent shell), NOT within your current shell itself. It sounds like what
you effectively want is for the subshell to 'feed back' information to
the parent shell, and then have the parent shell then 'cd' to the
desired directory (because no child process can do this on behalf any
parent process*). This 'feeding back' is a special-purpose requirement
of your task, and only you know the reasons for this requirement. An
alternative is to run each line of the script within the original
(a.k.a. parent) shell directly (as per Bernard's instructions) without
executing a subshell. This is the "special technique" I referred to in
the previous paragraph.
* I'm assume there are some non-portable exceptions to this ;-)
More information about the plug
mailing list