<?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: Executing commands with parameters in variables in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/executing-commands-with-parameters-in-variables/m-p/3970908#M758097</link>
    <description>Thanks to both of you for replies.&lt;BR /&gt;&lt;BR /&gt;Steven for the input.&lt;BR /&gt;&lt;BR /&gt;Dennis, I already tried a variaty of quoting&lt;BR /&gt;&lt;BR /&gt;${COMMAND} ${RUNCOMMAND}&lt;BR /&gt;${COMMAND} "${RUNCOMMAND}"&lt;BR /&gt;${COMMAND} \"${RUNCOMMAND}\"&lt;BR /&gt;&lt;BR /&gt;But it seems that using the version you wrote (without array though):&lt;BR /&gt;&lt;BR /&gt;$COMMAND "${RUNCOMMAND}"&lt;BR /&gt;&lt;BR /&gt;and executing the script using quotation on of the who -r command in the commandline, did the trick:&lt;BR /&gt;&lt;BR /&gt;/usr/contrib/bin/cmcpp.sh -P SERVER -p -u USER -c "who -r"&lt;BR /&gt;&lt;BR /&gt;Thanks.</description>
    <pubDate>Wed, 28 Mar 2007 06:34:56 GMT</pubDate>
    <dc:creator>Henrik Rasmussen</dc:creator>
    <dc:date>2007-03-28T06:34:56Z</dc:date>
    <item>
      <title>Executing commands with parameters in variables</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/executing-commands-with-parameters-in-variables/m-p/3970903#M758092</link>
      <description>&lt;!--!*#--&gt;I am making a shell script (/usr/bin/sh which I think is actually a POSIX Shell on HPUX 11.11).&lt;BR /&gt;&lt;BR /&gt;The script is used in a cluster when cron is executing a command, to determine whether the cluster package is present (or has failed over to another node), before actually executing the desired command.&lt;BR /&gt;&lt;BR /&gt;The shell script itself takes arguments to determine whether it has to change user, source the users profile etc. before executing the command, and it logs the output from the command to a file, giving the logfile the same name as the actual command or Oracle SQL script with the extention .log&lt;BR /&gt;&lt;BR /&gt;When all the check etc. is processed, the command is executed using 2 variables&lt;BR /&gt;&lt;BR /&gt;$COMMAND $RUNCOMMAND&lt;BR /&gt;&lt;BR /&gt;where the content of the variable&lt;BR /&gt;&lt;BR /&gt;$COMMAND may be /bin/su - USER -c&lt;BR /&gt;$RUNCOMMAND is for example who -r&lt;BR /&gt;&lt;BR /&gt;The echoed variables, just before execution, contains all desired commands and options, but the command which is executed after changing user, is only the command without options (in this case it only executes the who command, but is missing the -r option)&lt;BR /&gt;&lt;BR /&gt;I have tried a lot of different ways of quoting (both with and without escaping quotes with backslash). I also tried using eval and exec, but this doesn't help.&lt;BR /&gt;&lt;BR /&gt;How can I make sure that the command is executed with the options contained in the $RUNCOMMAND variable?&lt;BR /&gt;&lt;BR /&gt;Henrik</description>
      <pubDate>Wed, 28 Mar 2007 04:34:57 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/executing-commands-with-parameters-in-variables/m-p/3970903#M758092</guid>
      <dc:creator>Henrik Rasmussen</dc:creator>
      <dc:date>2007-03-28T04:34:57Z</dc:date>
    </item>
    <item>
      <title>Re: Executing commands with parameters in variables</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/executing-commands-with-parameters-in-variables/m-p/3970904#M758093</link>
      <description>The arguments to su are the arguments to sh.  And you need to quote the argument to -c:&lt;BR /&gt;$ $COMMAND "$RUNCOMMAND"&lt;BR /&gt;&lt;BR /&gt;&amp;gt;The echoed variables, just before execution, contains all desired commands and options&lt;BR /&gt;&lt;BR /&gt;You need to write yourself a printenv script that prints all of argv.  You'll see in your case you had two parms, who and -r.&lt;BR /&gt;After sh's -c, that -r may be a sh option.</description>
      <pubDate>Wed, 28 Mar 2007 04:49:09 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/executing-commands-with-parameters-in-variables/m-p/3970904#M758093</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2007-03-28T04:49:09Z</dc:date>
    </item>
    <item>
      <title>Re: Executing commands with parameters in variables</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/executing-commands-with-parameters-in-variables/m-p/3970905#M758094</link>
      <description>Shalom,&lt;BR /&gt;&lt;BR /&gt;try runing in sh -x mode or with set -x&lt;BR /&gt;&lt;BR /&gt;Environment problem likely.&lt;BR /&gt;&lt;BR /&gt;Please post output:&lt;BR /&gt;echo the variables just prior to execution.&lt;BR /&gt;&lt;BR /&gt;SEP</description>
      <pubDate>Wed, 28 Mar 2007 04:53:03 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/executing-commands-with-parameters-in-variables/m-p/3970905#M758094</guid>
      <dc:creator>Steven E. Protter</dc:creator>
      <dc:date>2007-03-28T04:53:03Z</dc:date>
    </item>
    <item>
      <title>Re: Executing commands with parameters in variables</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/executing-commands-with-parameters-in-variables/m-p/3970906#M758095</link>
      <description>A follow up, depending on COMMAND, sometimes you need to quote RUNCOMMAND and most of the time you don't.</description>
      <pubDate>Wed, 28 Mar 2007 04:57:05 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/executing-commands-with-parameters-in-variables/m-p/3970906#M758095</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2007-03-28T04:57:05Z</dc:date>
    </item>
    <item>
      <title>Re: Executing commands with parameters in variables</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/executing-commands-with-parameters-in-variables/m-p/3970907#M758096</link>
      <description>&amp;gt;depending on COMMAND, sometimes you need to quote RUNCOMMAND&lt;BR /&gt;&lt;BR /&gt;A simple solution is to have a variable per argument, then you always quote them.  You can use an array:&lt;BR /&gt;$ $COMMAND "${RUNCOMMAND[@]}"&lt;BR /&gt;</description>
      <pubDate>Wed, 28 Mar 2007 05:20:09 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/executing-commands-with-parameters-in-variables/m-p/3970907#M758096</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2007-03-28T05:20:09Z</dc:date>
    </item>
    <item>
      <title>Re: Executing commands with parameters in variables</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/executing-commands-with-parameters-in-variables/m-p/3970908#M758097</link>
      <description>Thanks to both of you for replies.&lt;BR /&gt;&lt;BR /&gt;Steven for the input.&lt;BR /&gt;&lt;BR /&gt;Dennis, I already tried a variaty of quoting&lt;BR /&gt;&lt;BR /&gt;${COMMAND} ${RUNCOMMAND}&lt;BR /&gt;${COMMAND} "${RUNCOMMAND}"&lt;BR /&gt;${COMMAND} \"${RUNCOMMAND}\"&lt;BR /&gt;&lt;BR /&gt;But it seems that using the version you wrote (without array though):&lt;BR /&gt;&lt;BR /&gt;$COMMAND "${RUNCOMMAND}"&lt;BR /&gt;&lt;BR /&gt;and executing the script using quotation on of the who -r command in the commandline, did the trick:&lt;BR /&gt;&lt;BR /&gt;/usr/contrib/bin/cmcpp.sh -P SERVER -p -u USER -c "who -r"&lt;BR /&gt;&lt;BR /&gt;Thanks.</description>
      <pubDate>Wed, 28 Mar 2007 06:34:56 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/executing-commands-with-parameters-in-variables/m-p/3970908#M758097</guid>
      <dc:creator>Henrik Rasmussen</dc:creator>
      <dc:date>2007-03-28T06:34:56Z</dc:date>
    </item>
  </channel>
</rss>

