<?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: using &amp;quot;procedures&amp;quot; into shell scripts in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/using-quot-procedures-quot-into-shell-scripts/m-p/2834471#M938587</link>
    <description>The parameters will be passed as arguements into the procedure just like the main script, they become localized to the procedure. You also don't need to specify the params on the procedure line&lt;BR /&gt;&lt;BR /&gt;proc()&lt;BR /&gt;{&lt;BR /&gt;  echo "${1} is the first param"&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;proc Test&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Also, the shift command will work just like it does in the main part of the script/ &lt;BR /&gt;&lt;BR /&gt;Todd Lehr&lt;BR /&gt;</description>
    <pubDate>Mon, 28 Oct 2002 16:55:54 GMT</pubDate>
    <dc:creator>Todd Lehr</dc:creator>
    <dc:date>2002-10-28T16:55:54Z</dc:date>
    <item>
      <title>using "procedures" into shell scripts</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/using-quot-procedures-quot-into-shell-scripts/m-p/2834469#M938585</link>
      <description>I know it is possible to use procedures in posix shell scripts like:&lt;BR /&gt;&lt;BR /&gt;procname () {&lt;BR /&gt;&lt;BR /&gt;command1&lt;BR /&gt;command1&lt;BR /&gt;...&lt;BR /&gt;}&lt;BR /&gt;recalled by "procname" into a script&lt;BR /&gt;&lt;BR /&gt;but can I pass any value to these procedures? &lt;BR /&gt;like:&lt;BR /&gt;&lt;BR /&gt;procname (arg1, arg2)&lt;BR /&gt;{&lt;BR /&gt;....&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;If I try I get a syntax error message.&lt;BR /&gt;&lt;BR /&gt;Thank You</description>
      <pubDate>Mon, 28 Oct 2002 16:53:03 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/using-quot-procedures-quot-into-shell-scripts/m-p/2834469#M938585</guid>
      <dc:creator>Mauro Gatti</dc:creator>
      <dc:date>2002-10-28T16:53:03Z</dc:date>
    </item>
    <item>
      <title>Re: using "procedures" into shell scripts</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/using-quot-procedures-quot-into-shell-scripts/m-p/2834470#M938586</link>
      <description>&lt;BR /&gt;Yes, you can pass arguments to functions in posix shell - see man sh-posix (there is a whole section on functions near the bottom and arguments to them).&lt;BR /&gt;&lt;BR /&gt;Basically the functions is defined as;&lt;BR /&gt;function &lt;NAME&gt;()&lt;BR /&gt;&lt;BR /&gt;and when you call it later you pass arguments like you would a script;&lt;BR /&gt;&lt;BR /&gt;&lt;NAME&gt; A B C&lt;BR /&gt;which are passed to the function as $1 $2 $3 and so on.&lt;BR /&gt;&lt;/NAME&gt;&lt;/NAME&gt;</description>
      <pubDate>Mon, 28 Oct 2002 16:54:55 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/using-quot-procedures-quot-into-shell-scripts/m-p/2834470#M938586</guid>
      <dc:creator>Stefan Farrelly</dc:creator>
      <dc:date>2002-10-28T16:54:55Z</dc:date>
    </item>
    <item>
      <title>Re: using "procedures" into shell scripts</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/using-quot-procedures-quot-into-shell-scripts/m-p/2834471#M938587</link>
      <description>The parameters will be passed as arguements into the procedure just like the main script, they become localized to the procedure. You also don't need to specify the params on the procedure line&lt;BR /&gt;&lt;BR /&gt;proc()&lt;BR /&gt;{&lt;BR /&gt;  echo "${1} is the first param"&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;proc Test&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Also, the shift command will work just like it does in the main part of the script/ &lt;BR /&gt;&lt;BR /&gt;Todd Lehr&lt;BR /&gt;</description>
      <pubDate>Mon, 28 Oct 2002 16:55:54 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/using-quot-procedures-quot-into-shell-scripts/m-p/2834471#M938587</guid>
      <dc:creator>Todd Lehr</dc:creator>
      <dc:date>2002-10-28T16:55:54Z</dc:date>
    </item>
    <item>
      <title>Re: using "procedures" into shell scripts</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/using-quot-procedures-quot-into-shell-scripts/m-p/2834472#M938588</link>
      <description>Rather than procedures you have functions which can be denoted by the keyword 'function' or by simply following an identifier with () BUT there are no formal parameters. The actual parameters are simply positional variables $1,$2,$3 ... that are specific to the function.&lt;BR /&gt;&lt;BR /&gt;e.g.&lt;BR /&gt;&lt;BR /&gt;my_function()&lt;BR /&gt;{&lt;BR /&gt;  echo "This is 1 ${1}"&lt;BR /&gt;  shift&lt;BR /&gt;  echo "This is 2 ${2}"&lt;BR /&gt;  return 0&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;my_function("One",Two")&lt;BR /&gt;&lt;BR /&gt;would result in&lt;BR /&gt;"This is 1 One"&lt;BR /&gt;"This is 2 Two"&lt;BR /&gt;</description>
      <pubDate>Mon, 28 Oct 2002 17:02:08 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/using-quot-procedures-quot-into-shell-scripts/m-p/2834472#M938588</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2002-10-28T17:02:08Z</dc:date>
    </item>
    <item>
      <title>Re: using "procedures" into shell scripts</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/using-quot-procedures-quot-into-shell-scripts/m-p/2834473#M938589</link>
      <description>Ooops, I'm an idiot.&lt;BR /&gt;&lt;BR /&gt;In the actual invocation of the function thare are no ()'s.&lt;BR /&gt;&lt;BR /&gt;my_function("One",Two") &lt;BR /&gt;&lt;BR /&gt;should be simply&lt;BR /&gt;my_function "One" "Two"&lt;BR /&gt;&lt;BR /&gt;I've got to learn to read over my answers before hitting 'Submit'.&lt;BR /&gt;&lt;BR /&gt;By the way, you can also capture the output of a function as well:&lt;BR /&gt;&lt;BR /&gt;my_result=$(my_funct2 345)&lt;BR /&gt;stat=${?}&lt;BR /&gt;&lt;BR /&gt;In this case ${my_result} would contain the stdout&lt;BR /&gt;of the function my_funct2 while ${stat} would contain the numerical result set by the 'return' in myfunct2.&lt;BR /&gt;&lt;BR /&gt; &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 28 Oct 2002 17:13:19 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/using-quot-procedures-quot-into-shell-scripts/m-p/2834473#M938589</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2002-10-28T17:13:19Z</dc:date>
    </item>
    <item>
      <title>Re: using "procedures" into shell scripts</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/using-quot-procedures-quot-into-shell-scripts/m-p/2834474#M938590</link>
      <description>Variables are also shared(usually) between functions and the calling program.  Example:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;#&lt;BR /&gt;# Functions&lt;BR /&gt;#&lt;BR /&gt;showit() {&lt;BR /&gt;        echo $VAR&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;VAR="some value"&lt;BR /&gt;showit&lt;BR /&gt;&lt;BR /&gt;VAR="some other value"&lt;BR /&gt;showit&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;man sh-posix for more info, particularly the "Functions" section.&lt;BR /&gt;&lt;BR /&gt;Darrell</description>
      <pubDate>Mon, 28 Oct 2002 19:16:23 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/using-quot-procedures-quot-into-shell-scripts/m-p/2834474#M938590</guid>
      <dc:creator>Darrell Allen</dc:creator>
      <dc:date>2002-10-28T19:16:23Z</dc:date>
    </item>
    <item>
      <title>Re: using "procedures" into shell scripts</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/using-quot-procedures-quot-into-shell-scripts/m-p/2834475#M938591</link>
      <description>Hi:&lt;BR /&gt;&lt;BR /&gt;You can kludge the passing of parameters by value by using 'typeset' declarations within the scope of the shell function.  A side benefit is inline self-documentation of the arguments passed.  Try running this:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;#&lt;BR /&gt;function me&lt;BR /&gt;{&lt;BR /&gt;  X=${1}.updated&lt;BR /&gt;  echo "fct_me : X=${X}"&lt;BR /&gt;}&lt;BR /&gt;function me2&lt;BR /&gt;{&lt;BR /&gt;  typeset X=$1&lt;BR /&gt;  X=${X}.updated&lt;BR /&gt;  echo "fct_me2: X=${X}"&lt;BR /&gt;}&lt;BR /&gt;#&lt;BR /&gt;X=ORIGINAL.VALUE&lt;BR /&gt;me $X&lt;BR /&gt;echo "global : X=${X}"&lt;BR /&gt;#&lt;BR /&gt;X=ORIGINAL.VALUE&lt;BR /&gt;me2 $X&lt;BR /&gt;echo "global : X=${X}"&lt;BR /&gt;#&lt;BR /&gt;exit 0&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Mon, 28 Oct 2002 20:11:49 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/using-quot-procedures-quot-into-shell-scripts/m-p/2834475#M938591</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2002-10-28T20:11:49Z</dc:date>
    </item>
  </channel>
</rss>

