[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Sourcing a script renders getopts impotent (or is it just me?)

From: Mun
Subject: Sourcing a script renders getopts impotent (or is it just me?)
Date: Thu, 16 Sep 2010 14:06:11 -0700
User-agent: Mutt/1.5.20 (2009-06-14)


Platform : Red Hat Enterprise Linux v5.5
Bash     : GNU bash, version 4.1.0(1)-release (x86_64-unknown-linux-gnu)

I have a script which uses getopts that I need to source in my
interactive shell.  The problem is that if I source it, getops behaves
as if no arguments were passed into the script.  Although, if I simply
run the script in a sub-process, getopts works correctly.

As an experiment, I echo'd all args prior to the getopts statement in
the script, and when the script was sourced all args were correctly
displayed.  So I'm at a loss as to why getopts doesn't seem to work when
the script is sourced.

On a side note, there is some error checking being done within the
script.  I would like the script execution to terminate but leave the
interactive shell running upon error detection (i.e., don't exit out of
the terminal sessioni).  Is there any way to accomplish that objective
in bash?



reply via email to

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