|
Home > Archive > Unix Shell > November 2005 > [BASH] shell functions don't work the same when opening sub-shells
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
[BASH] shell functions don't work the same when opening sub-shells
|
|
| Andrew Falanga 2005-11-28, 6:04 pm |
| Hi,
I've got a rather odd occurrance when I open a sub-shell for changes to
my environment. In my .bashrc file I have some shell functions that
I've written to help make life easier for me.
One of these functions takes an option, -p, and then a pattern to search
for. The pattern if found, is used in creating the sub-shell. I have
it setup that the function always defaults to a specific type of pattern
if the -p option is not provided.
When starting a new shell all works as it should, but after exiting a
sub-shell and using this function again, the function completely ignores
the -p option and simply uses the default. Can anyone shed some light
as to why for me?
---------------------------------------------
Andrew R. Falanga (a non-HP employee)
Hewlett-Packard Company
11311 Chinden Blvd.
Boise, Idaho
---------------------------------------------
Please note: The e-mail address is purposely
mangled. I do not wish my account at HP to
become a spam haven.
| |
| Lars Kellogg-Stedman 2005-11-28, 6:04 pm |
| > When starting a new shell all works as it should, but after exiting a
> sub-shell and using this function again, the function completely ignores
> the -p option and simply uses the default. Can anyone shed some light
> as to why for me?
Can you post the code so that we can take a look at it?
Have you tried running the script in debug (-x) mode? You can get trace
output for just the function in question by adding 'set -x' at the
beginning of the function (and 'set +x' before the function exits to
turn off tracing).
-- Lars
--
Lars Kellogg-Stedman <8273grkci8q8kgt@jetable.net>
This email address will expire on 2005-11-23.
| |
| Chris F.A. Johnson 2005-11-28, 6:04 pm |
| On 2005-11-28, Andrew Falanga wrote:
> Hi,
>
> I've got a rather odd occurrance when I open a sub-shell for changes to
> my environment.
A subshell can only change its own environment, not that of the
calling shell.
> In my .bashrc file I have some shell functions that
> I've written to help make life easier for me.
>
> One of these functions takes an option, -p, and then a pattern to search
> for. The pattern if found, is used in creating the sub-shell. I have
> it setup that the function always defaults to a specific type of pattern
> if the -p option is not provided.
>
> When starting a new shell all works as it should, but after exiting a
> sub-shell and using this function again, the function completely ignores
> the -p option and simply uses the default. Can anyone shed some light
> as to why for me?
If it changes the function, it is not a subshell. Please post some
code that exhibits the problem.
--
Chris F.A. Johnson, author | <http://cfaj.freeshell.org>
Shell Scripting Recipes: | My code in this post, if any,
A Problem-Solution Approach | is released under the
2005, Apress | GNU General Public Licence
| |
| Andrew Falanga 2005-11-28, 6:04 pm |
| Andrew Falanga wrote:
> Hi,
>
> I've got a rather odd occurrance when I open a sub-shell for changes to
> my environment. In my .bashrc file I have some shell functions that
> I've written to help make life easier for me.
>
> One of these functions takes an option, -p, and then a pattern to search
> for. The pattern if found, is used in creating the sub-shell. I have
> it setup that the function always defaults to a specific type of pattern
> if the -p option is not provided.
>
> When starting a new shell all works as it should, but after exiting a
> sub-shell and using this function again, the function completely ignores
> the -p option and simply uses the default. Can anyone shed some light
> as to why for me?
>
> ---------------------------------------------
> Andrew R. Falanga (a non-HP employee)
> Hewlett-Packard Company
> 11311 Chinden Blvd.
> Boise, Idaho
> ---------------------------------------------
> Please note: The e-mail address is purposely
> mangled. I do not wish my account at HP to
> become a spam haven.
Sorry for bugging people. I just managed to figure it out. I was
reading in the man page (imagine that!) that the OPTIND variable isn't
reset to 1 when getopts is called multiple times in the same shell
occurrance. I'm using getopts to find the options and since I'm calling
from the same occurrance of the shell, this was my problem.
Thanks for the help that would have been given and thanks for all the
help on my other issues I've asked about.
---------------------------------------------
Andrew R. Falanga (a non-HP employee)
Hewlett-Packard Company
11311 Chinden Blvd.
Boise, Idaho
---------------------------------------------
Please note: The e-mail address is purposely
mangled. I do not wish my account at HP to
become a spam haven.
|
|
|
|
|