<?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 Shift to Pass Parameters in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/using-shift-to-pass-parameters/m-p/3470676#M849500</link>
    <description>Of you can use the format-&lt;BR /&gt;echo ${10}&lt;BR /&gt; &lt;BR /&gt;For those above 9.&lt;BR /&gt; &lt;BR /&gt;HTH&lt;BR /&gt; &lt;BR /&gt;-- Rod Hills</description>
    <pubDate>Tue, 25 Jan 2005 11:29:42 GMT</pubDate>
    <dc:creator>Rodney Hills</dc:creator>
    <dc:date>2005-01-25T11:29:42Z</dc:date>
    <item>
      <title>Using Shift to Pass Parameters</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/using-shift-to-pass-parameters/m-p/3470671#M849495</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;I have a shell script which calls another script:&lt;BR /&gt;&lt;BR /&gt;write_backup_script_v12.ksh $1 $2 $3 $4 $5 $6 $7 $8 $9&lt;BR /&gt;&lt;BR /&gt;As you can see, script passes 9 parameters.  Want to pass more than 9 parameters.  How can I pass additional parameters beyond $9 ?   &lt;BR /&gt;&lt;BR /&gt;I've done research on "shift" but so far I don't see how to use shift to solve the problem.  Are there other ways besides "shift" ?  If not, could you give an example of how shift would be used in this case ?&lt;BR /&gt;&lt;BR /&gt;It's appreciated!&lt;BR /&gt;&lt;BR /&gt;Gil</description>
      <pubDate>Tue, 25 Jan 2005 11:14:21 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/using-shift-to-pass-parameters/m-p/3470671#M849495</guid>
      <dc:creator>Gilbert Standen_1</dc:creator>
      <dc:date>2005-01-25T11:14:21Z</dc:date>
    </item>
    <item>
      <title>Re: Using Shift to Pass Parameters</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/using-shift-to-pass-parameters/m-p/3470672#M849496</link>
      <description>Here is an example of how to use shift.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;numarg=$#&lt;BR /&gt;loop=$numarg+1&lt;BR /&gt;control=5&lt;BR /&gt;while (( control != $loop ))&lt;BR /&gt;do&lt;BR /&gt;  subject = "${subject} ${5}"&lt;BR /&gt;  shift&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;What this loop does is take all parameters after the fifth parameter and uses it to create the multi word subject for an email.&lt;BR /&gt;&lt;BR /&gt;It demonstrates the programming principle involved.&lt;BR /&gt;&lt;BR /&gt;SEP</description>
      <pubDate>Tue, 25 Jan 2005 11:22:43 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/using-shift-to-pass-parameters/m-p/3470672#M849496</guid>
      <dc:creator>Steven E. Protter</dc:creator>
      <dc:date>2005-01-25T11:22:43Z</dc:date>
    </item>
    <item>
      <title>Re: Using Shift to Pass Parameters</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/using-shift-to-pass-parameters/m-p/3470673#M849497</link>
      <description>Hi Gilbert,&lt;BR /&gt;&lt;BR /&gt;Yes, but not in base 10.&lt;BR /&gt;If you change the base with the baseXX command - EX base16 - then you could shift a or shift d to get past 10 shifts.&lt;BR /&gt;Note the max base is base64.&lt;BR /&gt;&lt;BR /&gt;Rgds,&lt;BR /&gt;Jeff</description>
      <pubDate>Tue, 25 Jan 2005 11:25:17 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/using-shift-to-pass-parameters/m-p/3470673#M849497</guid>
      <dc:creator>Jeff Schussele</dc:creator>
      <dc:date>2005-01-25T11:25:17Z</dc:date>
    </item>
    <item>
      <title>Re: Using Shift to Pass Parameters</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/using-shift-to-pass-parameters/m-p/3470674#M849498</link>
      <description>Gil,&lt;BR /&gt;you could use a temporary file to write/read the parameters.&lt;BR /&gt;Or pass the all the parameters enclosed by one set of double quotes.&lt;BR /&gt;write_backup_script_v12.ksh "$1 $2 ...$x" then use awk or cut to assign the parameters within the program.&lt;BR /&gt;&lt;BR /&gt;Regards</description>
      <pubDate>Tue, 25 Jan 2005 11:26:46 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/using-shift-to-pass-parameters/m-p/3470674#M849498</guid>
      <dc:creator>Peter Godron</dc:creator>
      <dc:date>2005-01-25T11:26:46Z</dc:date>
    </item>
    <item>
      <title>Re: Using Shift to Pass Parameters</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/using-shift-to-pass-parameters/m-p/3470675#M849499</link>
      <description>I guess I should have highlighted the fact that the shift value can *only* be 1 character.&lt;BR /&gt;Therefore in base64 you could use&lt;BR /&gt;1 - 10&lt;BR /&gt;a - z&lt;BR /&gt;A-Z&lt;BR /&gt;@ and _&lt;BR /&gt;for your 64 possible shift values.&lt;BR /&gt;&lt;BR /&gt;HTH,&lt;BR /&gt;Jeff</description>
      <pubDate>Tue, 25 Jan 2005 11:29:35 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/using-shift-to-pass-parameters/m-p/3470675#M849499</guid>
      <dc:creator>Jeff Schussele</dc:creator>
      <dc:date>2005-01-25T11:29:35Z</dc:date>
    </item>
    <item>
      <title>Re: Using Shift to Pass Parameters</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/using-shift-to-pass-parameters/m-p/3470676#M849500</link>
      <description>Of you can use the format-&lt;BR /&gt;echo ${10}&lt;BR /&gt; &lt;BR /&gt;For those above 9.&lt;BR /&gt; &lt;BR /&gt;HTH&lt;BR /&gt; &lt;BR /&gt;-- Rod Hills</description>
      <pubDate>Tue, 25 Jan 2005 11:29:42 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/using-shift-to-pass-parameters/m-p/3470676#M849500</guid>
      <dc:creator>Rodney Hills</dc:creator>
      <dc:date>2005-01-25T11:29:42Z</dc:date>
    </item>
    <item>
      <title>Re: Using Shift to Pass Parameters</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/using-shift-to-pass-parameters/m-p/3470677#M849501</link>
      <description>Another option under ksh is using an array-&lt;BR /&gt;set -A p "$@"&lt;BR /&gt; &lt;BR /&gt;within your script and this will assign array p as follows-&lt;BR /&gt;${p[0]} will be the first param&lt;BR /&gt;${p[1]} will be the second param&lt;BR /&gt;...&lt;BR /&gt;${p[12]} will be the thirteenth param&lt;BR /&gt;etc&lt;BR /&gt;etc&lt;BR /&gt; &lt;BR /&gt;HTH&lt;BR /&gt; &lt;BR /&gt;-- Rod Hills</description>
      <pubDate>Tue, 25 Jan 2005 12:37:48 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/using-shift-to-pass-parameters/m-p/3470677#M849501</guid>
      <dc:creator>Rodney Hills</dc:creator>
      <dc:date>2005-01-25T12:37:48Z</dc:date>
    </item>
    <item>
      <title>Re: Using Shift to Pass Parameters</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/using-shift-to-pass-parameters/m-p/3470678#M849502</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;These are all excellent replies and are very much appreciated.&lt;BR /&gt;&lt;BR /&gt;Peter Gordon's solutions were for me the most readily accessible, and since I'm a DBA and not a sysadmin, am taking the first one I can implement.  &lt;BR /&gt;&lt;BR /&gt;Somehow it's still not clear to me how shift is used to solve this.&lt;BR /&gt;&lt;BR /&gt;so here is my code, generalizable to i parameters (is there an upper limit on i using the code below ?)&lt;BR /&gt;&lt;BR /&gt;SCRIPT test.ksh (calls test_shift.ksh)&lt;BR /&gt;&lt;BR /&gt;test_shift.ksh "100 jim joe frank al mike gil susan kenny jane phil"&lt;BR /&gt;&lt;BR /&gt;SCRIPT test_shift.ksh (sets the values)&lt;BR /&gt;&lt;BR /&gt;echo $1&lt;BR /&gt;let i=1&lt;BR /&gt;let j=1&lt;BR /&gt;while [ "$i" -lt 12 ]&lt;BR /&gt;do&lt;BR /&gt;#echo $1 | cut -f"$i" -d' '&lt;BR /&gt;echo $1 | cut -f"$i" -d' ' | read parval&lt;BR /&gt;if [ "$i" -eq 1 ]&lt;BR /&gt;then&lt;BR /&gt;export var1=$parval&lt;BR /&gt;echo 'var1='$var1&lt;BR /&gt;elif [ "$i" -eq 2 ]&lt;BR /&gt;then&lt;BR /&gt;export var2=$parval&lt;BR /&gt;echo 'var2='$var2&lt;BR /&gt;elif [ "$i" -eq 10 ]&lt;BR /&gt;then&lt;BR /&gt;export var10=$parval&lt;BR /&gt;echo 'var10='$var10&lt;BR /&gt;elif [ "$i" -eq 11 ]&lt;BR /&gt;then&lt;BR /&gt;export var11=$parval&lt;BR /&gt;echo 'var11='$var11&lt;BR /&gt;fi&lt;BR /&gt;let i=$i+1&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;echo 'now execute the script commands'&lt;BR /&gt;&lt;BR /&gt;OUTPUT of scripts:&lt;BR /&gt;&lt;BR /&gt;# test.ksh&lt;BR /&gt;100 jim joe frank al mike gil susan kenny jane phil&lt;BR /&gt;var1=100&lt;BR /&gt;var2=jim&lt;BR /&gt;var10=jane&lt;BR /&gt;var11=phil&lt;BR /&gt;now execute the script commands&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 25 Jan 2005 13:43:31 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/using-shift-to-pass-parameters/m-p/3470678#M849502</guid>
      <dc:creator>Gilbert Standen_1</dc:creator>
      <dc:date>2005-01-25T13:43:31Z</dc:date>
    </item>
    <item>
      <title>Re: Using Shift to Pass Parameters</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/using-shift-to-pass-parameters/m-p/3470679#M849503</link>
      <description>Peter,&lt;BR /&gt;Oops I see now that the name is "Godron" and not "Gordon".  Please accept my apology.&lt;BR /&gt;Gil</description>
      <pubDate>Tue, 25 Jan 2005 14:07:08 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/using-shift-to-pass-parameters/m-p/3470679#M849503</guid>
      <dc:creator>Gilbert Standen_1</dc:creator>
      <dc:date>2005-01-25T14:07:08Z</dc:date>
    </item>
    <item>
      <title>Re: Using Shift to Pass Parameters</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/using-shift-to-pass-parameters/m-p/3470680#M849504</link>
      <description>Hi,&lt;BR /&gt;this is a simple example of how to use the shift command:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;typeset -i NUM_ARGS=0&lt;BR /&gt;NUM_ARGS="$#"&lt;BR /&gt;while [ "$NUM_ARGS" -gt 0 ]&lt;BR /&gt;do&lt;BR /&gt;echo "$1"&lt;BR /&gt;shift&lt;BR /&gt;NUM_ARGS=$(($NUM_ARGS - 1 ))&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;end of script args.sh...&lt;BR /&gt;Try executing args.sh like this:&lt;BR /&gt;&lt;BR /&gt;# args.sh "100" "jim" "john joe" "" "frank" "al" "mike o,brian" "gilberto gil" "susan" "kenny" "jane" "phil"&lt;BR /&gt;&lt;BR /&gt;in this way the script can handle more words as one parameter and even empty parameters.&lt;BR /&gt; &lt;BR /&gt;regards,&lt;BR /&gt;John K.&lt;BR /&gt;</description>
      <pubDate>Tue, 25 Jan 2005 14:19:56 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/using-shift-to-pass-parameters/m-p/3470680#M849504</guid>
      <dc:creator>john korterman</dc:creator>
      <dc:date>2005-01-25T14:19:56Z</dc:date>
    </item>
    <item>
      <title>Re: Using Shift to Pass Parameters</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/using-shift-to-pass-parameters/m-p/3470681#M849505</link>
      <description>If you want to create a variable number of variables, you can use the eval command. Start by grabbing all the parameters (limit is 1,024 parameters, probably not an issue) into an array, then create and assign each variable in a loop:&lt;BR /&gt; &lt;BR /&gt;#!/usr/bin/ksh&lt;BR /&gt;QTY=$#&lt;BR /&gt;set -A PARMS $@&lt;BR /&gt;COUNTER=0&lt;BR /&gt;while [ $COUNTER -lt $QTY ]&lt;BR /&gt;do&lt;BR /&gt;   let VARNUM=$COUNTER+1&lt;BR /&gt;   eval "var$VARNUM=${PARMS[$COUNTER]}"&lt;BR /&gt;   let COUNTER=$COUNTER+1&lt;BR /&gt;done&lt;BR /&gt;set | grep ^var&lt;BR /&gt; &lt;BR /&gt;The last statement (set) shows all the current variables. If you want the variable names to all have the same length, add the line: typeset -Z2 $VARNUM right after QTY=$#&lt;BR /&gt; &lt;BR /&gt;This script will create as many variables as you supply on the command line:&lt;BR /&gt; &lt;BR /&gt;myscript 1 2 3 4 5 6 7 8 9 0 11 22 33 44 555 6666 7777&lt;BR /&gt;var01=1&lt;BR /&gt;var02=2&lt;BR /&gt;var03=3&lt;BR /&gt;var04=4&lt;BR /&gt;var05=5&lt;BR /&gt;var06=6&lt;BR /&gt;var07=7&lt;BR /&gt;var08=8&lt;BR /&gt;var09=9&lt;BR /&gt;var10=0&lt;BR /&gt;var11=11&lt;BR /&gt;var12=22&lt;BR /&gt;var13=33&lt;BR /&gt;var14=44&lt;BR /&gt;var15=555&lt;BR /&gt;var16=6666&lt;BR /&gt;var17=7777</description>
      <pubDate>Tue, 25 Jan 2005 14:30:59 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/using-shift-to-pass-parameters/m-p/3470681#M849505</guid>
      <dc:creator>Bill Hassell</dc:creator>
      <dc:date>2005-01-25T14:30:59Z</dc:date>
    </item>
    <item>
      <title>Re: Using Shift to Pass Parameters</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/using-shift-to-pass-parameters/m-p/3470682#M849506</link>
      <description>Mr. Hassell,&lt;BR /&gt;An elegant solution which works great!&lt;BR /&gt;Gil</description>
      <pubDate>Tue, 25 Jan 2005 16:53:17 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/using-shift-to-pass-parameters/m-p/3470682#M849506</guid>
      <dc:creator>Gilbert Standen_1</dc:creator>
      <dc:date>2005-01-25T16:53:17Z</dc:date>
    </item>
    <item>
      <title>Re: Using Shift to Pass Parameters</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/using-shift-to-pass-parameters/m-p/3470683#M849507</link>
      <description>I took the parms method that Bill provided, and modified it to to pass (variable_name parameter) in ordered pairs and to set the variable to it's ordered pair parameter value.  Here is that version:&lt;BR /&gt;&lt;BR /&gt;#more parent_script_v2.ksh&lt;BR /&gt;newtest_v2.ksh FILE_LOC_1  /m02/oracle/scripts FILE_LOC_2  /m04/backups&lt;BR /&gt;&lt;BR /&gt;#more newtest_v2.ksh&lt;BR /&gt;#!/usr/bin/ksh&lt;BR /&gt;QTY=$#&lt;BR /&gt;set -A PARMS $@&lt;BR /&gt;COUNTER=0&lt;BR /&gt;while [ $COUNTER -lt $QTY ]&lt;BR /&gt;do&lt;BR /&gt;export VARNAME=${PARMS[COUNTER]}&lt;BR /&gt;let VARNUM=$COUNTER+1&lt;BR /&gt;eval "${VARNAME}=${PARMS[$VARNUM]}"&lt;BR /&gt;let COUNTER=$COUNTER+2&lt;BR /&gt;echo $VARNAME&lt;BR /&gt;done&lt;BR /&gt;set | grep ^FILE&lt;BR /&gt;echo 'execute the commands now'&lt;BR /&gt;echo $FILE_LOC_1&lt;BR /&gt;echo $FILE_LOC_2&lt;BR /&gt;&lt;BR /&gt;OUTPUT of parent_script_v2.ksh:&lt;BR /&gt;&lt;BR /&gt;#parent_script_v2.ksh&lt;BR /&gt;FILE_LOC_1&lt;BR /&gt;FILE_LOC_2&lt;BR /&gt;FILE_LOC_1=/m02/oracle/scripts&lt;BR /&gt;FILE_LOC_2=/m04/backups&lt;BR /&gt;execute the commands now&lt;BR /&gt;/m02/oracle/scripts&lt;BR /&gt;/m04/backups&lt;BR /&gt;&lt;BR /&gt;All help on this greatly appreciated!!&lt;BR /&gt;Gil&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 25 Jan 2005 18:01:38 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/using-shift-to-pass-parameters/m-p/3470683#M849507</guid>
      <dc:creator>Gilbert Standen_1</dc:creator>
      <dc:date>2005-01-25T18:01:38Z</dc:date>
    </item>
    <item>
      <title>Re: Using Shift to Pass Parameters</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/using-shift-to-pass-parameters/m-p/3470684#M849508</link>
      <description>Hello Gil,&lt;BR /&gt;&lt;BR /&gt;I do not think it coming handy to use shift.&lt;BR /&gt;It is vulnerable for bugs when you use so&lt;BR /&gt;many parameters.&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;ii=0&lt;BR /&gt;for xx&lt;BR /&gt;do&lt;BR /&gt;   ((ii = ii + 1 ))&lt;BR /&gt;   echo $xx $ii&lt;BR /&gt;   # if [ $ii -eq 1 -a "$xx" = "bla" ]&lt;BR /&gt;   # then&lt;BR /&gt;   #    bla bla ...&lt;BR /&gt;   # fi&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;output:&lt;BR /&gt;&lt;BR /&gt;test.sh 21 22 33 44 55 66 77 88 99 00 10 111 222 333&lt;BR /&gt;21 1&lt;BR /&gt;22 2&lt;BR /&gt;33 3&lt;BR /&gt;44 4&lt;BR /&gt;55 5&lt;BR /&gt;66 6&lt;BR /&gt;77 7&lt;BR /&gt;88 8&lt;BR /&gt;99 9&lt;BR /&gt;00 10&lt;BR /&gt;10 11&lt;BR /&gt;111 12&lt;BR /&gt;222 13&lt;BR /&gt;333 14&lt;BR /&gt;&lt;BR /&gt;Regards Gregor</description>
      <pubDate>Wed, 26 Jan 2005 06:12:30 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/using-shift-to-pass-parameters/m-p/3470684#M849508</guid>
      <dc:creator>Weertman</dc:creator>
      <dc:date>2005-01-26T06:12:30Z</dc:date>
    </item>
    <item>
      <title>Re: Using Shift to Pass Parameters</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/using-shift-to-pass-parameters/m-p/3470685#M849509</link>
      <description>Discovered that "export variable_name" does what is needed for my purposes also (can export a large number of variables).&lt;BR /&gt;&lt;BR /&gt;Question:&lt;BR /&gt;Are there any cases in which passing of parameters at the time a subroutine is called on the command line must be used INSTEAD OF using "export", i.e cases where export will fail ?  I tried calling a subroutine script with " &amp;amp;" at the end of the command and it still knew what the value of the variable was thanks to export.&lt;BR /&gt;&lt;BR /&gt;When I asked the question, it hadn't occurred to me that there was any way other than including the commands at the command line when invoking the other script(s), so perhaps I should have phrased the question more generally.&lt;BR /&gt;</description>
      <pubDate>Wed, 26 Jan 2005 15:38:06 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/using-shift-to-pass-parameters/m-p/3470685#M849509</guid>
      <dc:creator>Gilbert Standen_1</dc:creator>
      <dc:date>2005-01-26T15:38:06Z</dc:date>
    </item>
    <item>
      <title>Re: Using Shift to Pass Parameters</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/using-shift-to-pass-parameters/m-p/3470686#M849510</link>
      <description>The export mechanism would tend to be more cumbersome. Also consider the case of recursive scripts and functions. Exporting would prove difficult but parameters would happily create instances as needed.&lt;BR /&gt;</description>
      <pubDate>Wed, 26 Jan 2005 15:45:11 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/using-shift-to-pass-parameters/m-p/3470686#M849510</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2005-01-26T15:45:11Z</dc:date>
    </item>
  </channel>
</rss>

