[PLUG] bash question

Denis Heidtmann denis.heidtmann at gmail.com
Sat Apr 3 20:53:06 UTC 2010


On Sat, Apr 3, 2010 at 11:34 AM, Fred James <fredjame at fredjame.cnc.net>wrote:

> Denis Heidtmann wrote:
> > [many omissions for bevity]
>
> > Your explanation does indeed help me understand what gdmwhich() does.
> > Since my script resides in one of my directories not in the $PATH, I
> chose
> > to execute it above the setting of IFS to : using its fully qualified
> path.
> >  It executes fine, and does what is intended.  However, if I source my
> > script rather than execute it, the argument does not get passed.  I am
> > assuming now that this behavior is normal for dash.  My remedies are 1)
> to
> > execute my script in PostSession/default, in which case the argument is
> > passed as expected, or 2) source a special script which has the argument
> > hard-coded in it.
> >
> > To decide which remedy to choose I would like to know why the Debian
> Policy
> > states that scripts used should be sourced.  If violating that policy
> would
> > cause no problem that would be my choice.  That is what I have set up at
> > present, and I have noticed no problems.  However, lacking the
> understanding
> > of the motivation for the Policy, I cannot be certain that a problem will
> > not arise.
> >
> > So, in summary, my original question was: Why does the argument not get
> > passed with a sourced invocation? (answer: normal behavior of dash).  The
> > question now is: If I execute a script from PostSession/default will I
> cause
> > a problem?
> >
> > Thanks so much for the effort you  have put in toward my education.
> >
> > -Denis
> >
> Denis Heidtmann
> While the most straight forward way could be to simply hard code the
> full_path_name_to_your_executable into the appropriate Default
> executable, that would create a maintenance problem with Default, and
> could cause unexpected behavior should your_executable not be found
> there, or fail for some reason (i.e., one would have to add all of the
> appropriate exception handling routines to Default, and then do it all
> over again, including the appropriate testing, every time there was an
> upgrade.
>
> But to add a line or two to Default to (a) get the full path name, and
> then (b) execute your_executable, changes the complexion ... for one
> thing, gdmwhich has a bit of error handling in  that it returns nothing
> (empty string) if it cannot find your_executable, and nothing on a line
> by itself (within a program, in this case Default) doesn't do anything,
> so there isn't a problem.  OK?
>
> Now, suppose we thought ... oh, but there may be some unknown number of
> new executables that might be called within Default (at some time in the
> future?)  Well then we might want to make a text file to contain the
> list of those new executables, and add a routine to Default to browse
> through that list, finding the executables, complete their paths, and
> call them each sequentially.
>
> That much said, perhaps we should turn our attention to "if I source my
> script rather than execute it, the argument does not get passed."  Could
> you please, state what is happening here?  For example:  From withing
> Default you are calling script_1, is that correct?
>
> If that is correct, are you attempting to pass an argument to script_1?
>
> And then, what does script_1 do?  For example:  Does it try to return
> some value to Default?
>
> Any clarification would be most welcome
> Regards
> Fred James
>

I realize the simple approach of hard-coding the full path to my script
presents a maintenance problem, but perhaps I am willing to live with that.

My script simply writes the date and time followed by a word of text to a
log file.  The word of text is the argument passed to my script, or if no
argument, the word of text is "UNKNOWN".  If my script is invoked from
Default by being sourced, no argument is received by my script, so the entry
in my log is labeled "UNKNOWN".  I have currently solved this problem by
detecting that the script was sourced, assume it was invoked from Default,
and set the word of text to "Logout".  I can refine this by checking that
Default was the caller; I have not done that yet.

If something goes wrong, for whatever reason, I may lose some data, but that
is a risk I am willing to take.  Only if calling my script throws an error
within Default such that Default  fails to do its intended job am I
concerned.  Since Default does nothing at present, I feel pretty safe.

-Denis



More information about the PLUG mailing list