<?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: script doesn't execute the command but echo is okay in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/script-doesn-t-execute-the-command-but-echo-is-okay/m-p/4761872#M657172</link>
    <description>Hi,&lt;BR /&gt;&lt;BR /&gt;Instead of execute $CMD try directly:&lt;BR /&gt;mycommand -a -d -c $cg_grp -o&lt;BR /&gt;&lt;BR /&gt;Rgds.</description>
    <pubDate>Sat, 05 Mar 2011 11:00:56 GMT</pubDate>
    <dc:creator>Jose Mosquera</dc:creator>
    <dc:date>2011-03-05T11:00:56Z</dc:date>
    <item>
      <title>script doesn't execute the command but echo is okay</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-doesn-t-execute-the-command-but-echo-is-okay/m-p/4761866#M657166</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;I have tried this couple of times but still not sure why.  The echo output show the command syntax is correct but if I treat the CMD as a command to execute it directly, the set -x show it has some extra character on it and this will cause the command to fail.&lt;BR /&gt;&lt;BR /&gt;set -x&lt;BR /&gt;SERVERGROUP="myserver 1:myserver_2"&lt;BR /&gt;CLNID=1&lt;BR /&gt;IFS=:&lt;BR /&gt;for i in $SERVERGROUP&lt;BR /&gt;        do&lt;BR /&gt;                cg_grp="${cg_grp} '$i' $CLNID"&lt;BR /&gt;        done&lt;BR /&gt;        CMD="mycommand -a -d -c"$cg_grp" -o"&lt;BR /&gt;        echo $CMD&lt;BR /&gt;        $CMD&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;++ SERVERGROUP='myserver 1:myserver_2'&lt;BR /&gt;++ CLNID=1&lt;BR /&gt;++ IFS=:&lt;BR /&gt;++ for i in '$SERVERGROUP'&lt;BR /&gt;++ cg_grp=' '\''myserver 1'\'' 1'&lt;BR /&gt;++ for i in '$SERVERGROUP'&lt;BR /&gt;++ cg_grp=' '\''myserver 1'\'' 1 '\''myserver_2'\'' 1'&lt;BR /&gt;++ CMD='mycommand -a -d -c '\''myserver 1'\'' 1 '\''myserver_2'\'' 1 -o'&lt;BR /&gt;++ echo 'mycommand -a -d -c '\''myserver 1'\'' 1 '\''myserver_2'\'' 1 -o'&lt;BR /&gt;mycommand -a -d -c 'myserver 1' 1 'myserver_2' 1 -o&lt;BR /&gt;++ 'mycommand -a -d -c '\''myserver 1'\'' 1 '\''myserver_2'\'' 1 -o'&lt;BR /&gt;&lt;BR /&gt;Correct command should be &lt;BR /&gt;mycommand -a -d -c 'myserver 1' 1 'myserver_2' 1 -o&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Sat, 05 Mar 2011 08:47:23 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-doesn-t-execute-the-command-but-echo-is-okay/m-p/4761866#M657166</guid>
      <dc:creator>kholikt</dc:creator>
      <dc:date>2011-03-05T08:47:23Z</dc:date>
    </item>
    <item>
      <title>Re: script doesn't execute the command but echo is okay</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-doesn-t-execute-the-command-but-echo-is-okay/m-p/4761867#M657167</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;When you try to executes $CMD. This "mycommand" is other script? Yes, then:&lt;BR /&gt;1.- Have enought execution permissions? &lt;BR /&gt;2.- Must begging with:&lt;BR /&gt;./mycommand...&lt;BR /&gt;-or-&lt;BR /&gt;sh mycommand...&lt;BR /&gt;This last one depend of shell interpreter that you are using (sh, ksh, etc).&lt;BR /&gt;&lt;BR /&gt;Rgds.</description>
      <pubDate>Sat, 05 Mar 2011 10:09:20 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-doesn-t-execute-the-command-but-echo-is-okay/m-p/4761867#M657167</guid>
      <dc:creator>Jose Mosquera</dc:creator>
      <dc:date>2011-03-05T10:09:20Z</dc:date>
    </item>
    <item>
      <title>Re: script doesn't execute the command but echo is okay</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-doesn-t-execute-the-command-but-echo-is-okay/m-p/4761868#M657168</link>
      <description>a quick and dirty fix of course is to put the command in a temporary file and run that file as script.&lt;BR /&gt;&lt;BR /&gt; echo $CMD &amp;gt; tmp_cmd&lt;BR /&gt; chmod u+x tmp_cmd&lt;BR /&gt; ./tmp_cmd&lt;BR /&gt; cg_grp=""&lt;BR /&gt; rm -f tmp_cmd</description>
      <pubDate>Sat, 05 Mar 2011 10:22:37 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-doesn-t-execute-the-command-but-echo-is-okay/m-p/4761868#M657168</guid>
      <dc:creator>kholikt</dc:creator>
      <dc:date>2011-03-05T10:22:37Z</dc:date>
    </item>
    <item>
      <title>Re: script doesn't execute the command but echo is okay</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-doesn-t-execute-the-command-but-echo-is-okay/m-p/4761869#M657169</link>
      <description>mycommand is just a binary and yes I have the permission.</description>
      <pubDate>Sat, 05 Mar 2011 10:35:39 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-doesn-t-execute-the-command-but-echo-is-okay/m-p/4761869#M657169</guid>
      <dc:creator>kholikt</dc:creator>
      <dc:date>2011-03-05T10:35:39Z</dc:date>
    </item>
    <item>
      <title>Re: script doesn't execute the command but echo is okay</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-doesn-t-execute-the-command-but-echo-is-okay/m-p/4761870#M657170</link>
      <description>quick and dirty I tired the following it will work&lt;BR /&gt;&lt;BR /&gt;echo $CMD &amp;gt; tmp_cmd&lt;BR /&gt;chmod u+x tmp_cmd&lt;BR /&gt;./tmp_cmd&lt;BR /&gt;cg_grp=""&lt;BR /&gt;rm -f tmp_cmd</description>
      <pubDate>Sat, 05 Mar 2011 10:36:15 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-doesn-t-execute-the-command-but-echo-is-okay/m-p/4761870#M657170</guid>
      <dc:creator>kholikt</dc:creator>
      <dc:date>2011-03-05T10:36:15Z</dc:date>
    </item>
    <item>
      <title>Re: script doesn't execute the command but echo is okay</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-doesn-t-execute-the-command-but-echo-is-okay/m-p/4761871#M657171</link>
      <description>&lt;!--!*#--&gt;Looks like the "set -x" output uses single quotes to indicate expansion results, somehow. Which shell are you using to run this?&lt;BR /&gt;&lt;BR /&gt;Because you're setting IFS=:, the $CMD is not expanded into command + arguments for execution in the normal way.&lt;BR /&gt;&lt;BR /&gt;The normal way would be:&lt;BR /&gt;$0 (the command to execute) = mycommand&lt;BR /&gt;$1 = -a&lt;BR /&gt;$2 = -d&lt;BR /&gt;$3 = -c&lt;BR /&gt;$4 = 'myserver 1'1&lt;BR /&gt;$5 = 'myserver_2'1&lt;BR /&gt;$6 = -o&lt;BR /&gt;&lt;BR /&gt;Because you've set IFS=:, space isn't a separator character anymore, and you're getting:&lt;BR /&gt;$0 = mycommand -a -d -c 'myserver 1'1 'myserver_2'1 -o&lt;BR /&gt;&lt;BR /&gt;which obviously is unlikely to be found in the PATH as an executable command.&lt;BR /&gt;&lt;BR /&gt;I would suggest getting rid of the custom IFS setting as soon as it is not needed any more: IFS is a classic way to shoot yourself in the foot.&lt;BR /&gt;&lt;BR /&gt;set -x&lt;BR /&gt;SERVERGROUP="myserver 1:myserver_2"&lt;BR /&gt;CLNID=1&lt;BR /&gt;IFS=:&lt;BR /&gt;for i in $SERVERGROUP&lt;BR /&gt;do&lt;BR /&gt;        cg_grp="${cg_grp} '$i' $CLNID"&lt;BR /&gt;done&lt;BR /&gt;unset IFS  #resume standard behavior&lt;BR /&gt;CMD="mycommand -a -d -c"$cg_grp" -o"&lt;BR /&gt;echo $CMD&lt;BR /&gt;$CMD&lt;BR /&gt;&lt;BR /&gt;My test of this modified script fragment produced this result. If I understand correctly, this is what you wanted:&lt;BR /&gt;&lt;BR /&gt;+ SERVERGROUP=myserver 1:myserver_2&lt;BR /&gt;+ CLNID=1&lt;BR /&gt;+ IFS=:&lt;BR /&gt;+ cg_grp= 'myserver 1' 1&lt;BR /&gt;+ cg_grp= 'myserver 1' 1 'myserver_2' 1&lt;BR /&gt;+ unset IFS&lt;BR /&gt;+ CMD=mycommand -a -d -c 'myserver 1' 1 'myserver_2' 1 -o&lt;BR /&gt;+ echo mycommand -a -d -c 'myserver 1' 1 'myserver_2' 1 -o&lt;BR /&gt;mycommand -a -d -c 'myserver 1' 1 'myserver_2' 1 -o&lt;BR /&gt;+ mycommand -a -d -c 'myserver 1' 1 'myserver_2' 1 -o&lt;BR /&gt;ifstest.sh: 1: mycommand: not found&lt;BR /&gt;&lt;BR /&gt;MK</description>
      <pubDate>Sat, 05 Mar 2011 10:50:34 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-doesn-t-execute-the-command-but-echo-is-okay/m-p/4761871#M657171</guid>
      <dc:creator>Matti_Kurkela</dc:creator>
      <dc:date>2011-03-05T10:50:34Z</dc:date>
    </item>
    <item>
      <title>Re: script doesn't execute the command but echo is okay</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-doesn-t-execute-the-command-but-echo-is-okay/m-p/4761872#M657172</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;Instead of execute $CMD try directly:&lt;BR /&gt;mycommand -a -d -c $cg_grp -o&lt;BR /&gt;&lt;BR /&gt;Rgds.</description>
      <pubDate>Sat, 05 Mar 2011 11:00:56 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-doesn-t-execute-the-command-but-echo-is-okay/m-p/4761872#M657172</guid>
      <dc:creator>Jose Mosquera</dc:creator>
      <dc:date>2011-03-05T11:00:56Z</dc:date>
    </item>
    <item>
      <title>Re: script doesn't execute the command but echo is okay</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-doesn-t-execute-the-command-but-echo-is-okay/m-p/4761873#M657173</link>
      <description>Hi:&lt;BR /&gt;&lt;BR /&gt;&amp;gt; Matiti: IFS is a classic way to shoot yourself in the foot.&lt;BR /&gt;&lt;BR /&gt;This is very true.  In shell's I like to do:&lt;BR /&gt;&lt;BR /&gt;...&lt;BR /&gt;OLDIFS=${IFS}&lt;BR /&gt;IFS=":"&lt;BR /&gt;...&lt;BR /&gt;IFS=${OLDIFS}&lt;BR /&gt;...&lt;BR /&gt;&lt;BR /&gt;The default value for IFS consists of a space, a tab and a newline character.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Sat, 05 Mar 2011 14:13:41 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-doesn-t-execute-the-command-but-echo-is-okay/m-p/4761873#M657173</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2011-03-05T14:13:41Z</dc:date>
    </item>
  </channel>
</rss>

