<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Posix shell scripting using functions in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/posix-shell-scripting-using-functions/m-p/2726745#M721744</link>
    <description>I'm not sure if this will work, but couldn't you write a wrapper function and have it execute the function you want.&lt;BR /&gt;&lt;BR /&gt;example, I have function do&lt;BR /&gt;do()&lt;BR /&gt;{&lt;BR /&gt; dofct=$1&lt;BR /&gt; shift&lt;BR /&gt; ${VERBOSE} &amp;amp;&amp;amp; echo "$dofct function entered."&lt;BR /&gt; eval "$dofct $@"&lt;BR /&gt; return&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;Then in my scripts I would run&lt;BR /&gt;&lt;BR /&gt;do SomeFunction arg1 arg2 ...&lt;BR /&gt;&lt;BR /&gt;Then "do" would optionally display trace statement and then execute the required function.&lt;BR /&gt;&lt;BR /&gt;-- Rod Hills</description>
    <pubDate>Fri, 17 May 2002 18:18:48 GMT</pubDate>
    <dc:creator>Rodney Hills</dc:creator>
    <dc:date>2002-05-17T18:18:48Z</dc:date>
    <item>
      <title>Posix shell scripting using functions</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/posix-shell-scripting-using-functions/m-p/2726744#M721743</link>
      <description>I am writing a script using many functions.  Within the script, I use an environment variable (VERBOSE) set to /bin/true if I want more verbose output which spits out additional information for me to use while trouble shooting.&lt;BR /&gt;&lt;BR /&gt;An example of how I use it follows:&lt;BR /&gt;&lt;BR /&gt;SomeFunction()&lt;BR /&gt;{&lt;BR /&gt;  ${VERBOSE} &amp;amp;&amp;amp; echo "SomeFunction function entered."&lt;BR /&gt;  rc=0&lt;BR /&gt;  &lt;BR /&gt;  :&lt;BR /&gt;  # other logic&lt;BR /&gt;  :&lt;BR /&gt;  return ${rc}&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;I want to standardize on the format of all functions I create, and would like to have the VERBOSE line be dynamic without having to change the text of the message so it reflects the real name of the function in the example code above.&lt;BR /&gt;&lt;BR /&gt;The script name can be referenced via $0, and arguments to the script via $1, $2,... etc.  Is there some other way to reference a function name within a script?  I've been unable to find any reference in the man page sh-posix to any environment variable names, etc that would reflect the function name within the script.&lt;BR /&gt;&lt;BR /&gt;Thanks in advance for any help!</description>
      <pubDate>Fri, 17 May 2002 17:54:17 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/posix-shell-scripting-using-functions/m-p/2726744#M721743</guid>
      <dc:creator>Kurt Renner</dc:creator>
      <dc:date>2002-05-17T17:54:17Z</dc:date>
    </item>
    <item>
      <title>Re: Posix shell scripting using functions</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/posix-shell-scripting-using-functions/m-p/2726745#M721744</link>
      <description>I'm not sure if this will work, but couldn't you write a wrapper function and have it execute the function you want.&lt;BR /&gt;&lt;BR /&gt;example, I have function do&lt;BR /&gt;do()&lt;BR /&gt;{&lt;BR /&gt; dofct=$1&lt;BR /&gt; shift&lt;BR /&gt; ${VERBOSE} &amp;amp;&amp;amp; echo "$dofct function entered."&lt;BR /&gt; eval "$dofct $@"&lt;BR /&gt; return&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;Then in my scripts I would run&lt;BR /&gt;&lt;BR /&gt;do SomeFunction arg1 arg2 ...&lt;BR /&gt;&lt;BR /&gt;Then "do" would optionally display trace statement and then execute the required function.&lt;BR /&gt;&lt;BR /&gt;-- Rod Hills</description>
      <pubDate>Fri, 17 May 2002 18:18:48 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/posix-shell-scripting-using-functions/m-p/2726745#M721744</guid>
      <dc:creator>Rodney Hills</dc:creator>
      <dc:date>2002-05-17T18:18:48Z</dc:date>
    </item>
    <item>
      <title>Re: Posix shell scripting using functions</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/posix-shell-scripting-using-functions/m-p/2726746#M721745</link>
      <description>Hi Kurt:&lt;BR /&gt;&lt;BR /&gt;I don't know of any way to directly accomplish your objective as defined.  Here's what I've sometimes done in shell scripts:&lt;BR /&gt;&lt;BR /&gt;Declare a local variable within each function to which you assign the name of the function:&lt;BR /&gt;&lt;BR /&gt;When you need to produce output you can include the defined function name and optionally the linenumber of the function.&lt;BR /&gt;&lt;BR /&gt;...&lt;BR /&gt;myfunction()&lt;BR /&gt;{ &lt;BR /&gt;typeset -r WHO=myfunction&lt;BR /&gt;...&lt;BR /&gt;echo "Error in $WHO at $LINENO"&lt;BR /&gt;]&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Fri, 17 May 2002 18:25:57 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/posix-shell-scripting-using-functions/m-p/2726746#M721745</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2002-05-17T18:25:57Z</dc:date>
    </item>
    <item>
      <title>Re: Posix shell scripting using functions</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/posix-shell-scripting-using-functions/m-p/2726747#M721746</link>
      <description>Hi Kurt:&lt;BR /&gt;&lt;BR /&gt;There is unfortunately no way to do this; there have been many times when I looked for a method without success. Not that it helps you but Perl does have a built-in function 'caller()' that does exactly this; e.g.:&lt;BR /&gt;&lt;BR /&gt;$this_func_name = (caller(0))[3];&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 17 May 2002 18:40:23 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/posix-shell-scripting-using-functions/m-p/2726747#M721746</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2002-05-17T18:40:23Z</dc:date>
    </item>
    <item>
      <title>Re: Posix shell scripting using functions</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/posix-shell-scripting-using-functions/m-p/2726748#M721747</link>
      <description>Thanks for all the responses.  I had a feeling that what A. Clay said was the case, but wanted to run it by.&lt;BR /&gt;&lt;BR /&gt;I like Rodney's idea, but it is a little messy with too many levels of function calls.  I prefer to keep it simpler for those on my team that are not regular shell scripters.&lt;BR /&gt;&lt;BR /&gt;James has a good idea also.  It is a little better than what I am doing, but it still is not as generic as I was hoping to be able to make my "template function".&lt;BR /&gt;&lt;BR /&gt;If I find any other way, I'll be sure to let you know within this posting.&lt;BR /&gt;&lt;BR /&gt;Thanks again to each one of you.</description>
      <pubDate>Fri, 17 May 2002 19:24:36 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/posix-shell-scripting-using-functions/m-p/2726748#M721747</guid>
      <dc:creator>Kurt Renner</dc:creator>
      <dc:date>2002-05-17T19:24:36Z</dc:date>
    </item>
  </channel>
</rss>

