<?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: Echo PIPE character which stored in variable in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/echo-pipe-character-which-stored-in-variable/m-p/3606202#M19175</link>
    <description>Wow! You are right! The "| grep new" was not printed in the log file. That proved that the "| grep new" was not part of the arg.&lt;BR /&gt;&lt;BR /&gt;By the way, how come the last statement behaves as I expected? (i.e. the "| grep new" is executed).</description>
    <pubDate>Thu, 18 Aug 2005 21:45:20 GMT</pubDate>
    <dc:creator>Eric Leung_2</dc:creator>
    <dc:date>2005-08-18T21:45:20Z</dc:date>
    <item>
      <title>Echo PIPE character which stored in variable</title>
      <link>https://community.hpe.com/t5/operating-system-linux/echo-pipe-character-which-stored-in-variable/m-p/3606197#M19170</link>
      <description>Assuming that:&lt;BR /&gt;$*= "rdo ls -l /tmp | grep new"&lt;BR /&gt;&lt;BR /&gt;The shell script:&lt;BR /&gt;#!/bin/ksh&lt;BR /&gt;CMD=`echo $* | cut -f1- -d " "`&lt;BR /&gt;printf "%s: [%s]&amp;gt; %s\n"  "`date`" $LOGNAME "${CMD}" &amp;gt;&amp;gt; /root/rdo.log&lt;BR /&gt;${CMD}&lt;BR /&gt;&lt;BR /&gt;The above script refers. I wanted to write the $* into /root/rdo.log. However, I got the following output:&lt;BR /&gt;&lt;BR /&gt;Thu Aug 18 09:45:54 HKT 2005: [root]&amp;gt; ls -l /tmp&lt;BR /&gt;&lt;BR /&gt;The "| grep new" was lost.&lt;BR /&gt;&lt;BR /&gt;I think that it was because the "| grep new" was interpreted as part of the printf command. What change is necessary so that the whole command can be recorded correctly?&lt;BR /&gt;&lt;BR /&gt;Thanks</description>
      <pubDate>Wed, 17 Aug 2005 21:27:01 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/echo-pipe-character-which-stored-in-variable/m-p/3606197#M19170</guid>
      <dc:creator>Eric Leung_2</dc:creator>
      <dc:date>2005-08-17T21:27:01Z</dc:date>
    </item>
    <item>
      <title>Re: Echo PIPE character which stored in variable</title>
      <link>https://community.hpe.com/t5/operating-system-linux/echo-pipe-character-which-stored-in-variable/m-p/3606198#M19171</link>
      <description>It's probably because arguments to the shell scripts are not quoted.&lt;BR /&gt;&lt;BR /&gt;For example if you run your shell script as&lt;BR /&gt;&lt;BR /&gt;$ ./test.sh rdo ls -l /tmp | grep new&lt;BR /&gt;&lt;BR /&gt;your shell script will only see the part up to the pipe symbol (that's what gets logged).&lt;BR /&gt;&lt;BR /&gt;However if arguments to your shell script are passed in single or double quotes as&lt;BR /&gt;&lt;BR /&gt;$ ./test.sh 'rdo ls -l /tmp | grep new'&lt;BR /&gt;&lt;BR /&gt;then the whole command will be logged correctly. However pipe symbol will lose its special meaning (because of quotes) so the last line of the script should be changed to&lt;BR /&gt;&lt;BR /&gt;eval ${CMD}&lt;BR /&gt;&lt;BR /&gt;for the shell to re-evalute the command and reassign the special meaning to the pipe symbol.</description>
      <pubDate>Thu, 18 Aug 2005 04:24:56 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/echo-pipe-character-which-stored-in-variable/m-p/3606198#M19171</guid>
      <dc:creator>Ermin Borovac</dc:creator>
      <dc:date>2005-08-18T04:24:56Z</dc:date>
    </item>
    <item>
      <title>Re: Echo PIPE character which stored in variable</title>
      <link>https://community.hpe.com/t5/operating-system-linux/echo-pipe-character-which-stored-in-variable/m-p/3606199#M19172</link>
      <description>You can try as,&lt;BR /&gt;&lt;BR /&gt;#!/bin/ksh&lt;BR /&gt;CMD=`echo $* | cut -f1- -d " "`&lt;BR /&gt;printf "%s: [%s]&amp;gt; %s\n" "`date`" $LOGNAME "${CMD}" &amp;gt;&amp;gt; /root/rdo.log&lt;BR /&gt;echo ${CMD} | ksh&lt;BR /&gt;&lt;BR /&gt;Pass arguments with " (double quote) or with ' (single quote).&lt;BR /&gt;&lt;BR /&gt;hth.</description>
      <pubDate>Thu, 18 Aug 2005 06:13:49 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/echo-pipe-character-which-stored-in-variable/m-p/3606199#M19172</guid>
      <dc:creator>Muthukumar_5</dc:creator>
      <dc:date>2005-08-18T06:13:49Z</dc:date>
    </item>
    <item>
      <title>Re: Echo PIPE character which stored in variable</title>
      <link>https://community.hpe.com/t5/operating-system-linux/echo-pipe-character-which-stored-in-variable/m-p/3606200#M19173</link>
      <description>Thanks Experts.&lt;BR /&gt;&lt;BR /&gt;Actually, the problem is at the printf statement.&lt;BR /&gt;&lt;BR /&gt;In fact, this script is called by C program, which can successfully pass the "rdo ls -l /tmp | grep new" to this shell script and  the command "ls -l /tmp | grep new" can also run as expected.&lt;BR /&gt;&lt;BR /&gt;However, the /root/rdo.log can only log "ls -l /tmp" instead of what I want "ls -l /tmp | grep new".&lt;BR /&gt;&lt;BR /&gt;Any other idea?</description>
      <pubDate>Thu, 18 Aug 2005 20:55:30 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/echo-pipe-character-which-stored-in-variable/m-p/3606200#M19173</guid>
      <dc:creator>Eric Leung_2</dc:creator>
      <dc:date>2005-08-18T20:55:30Z</dc:date>
    </item>
    <item>
      <title>Re: Echo PIPE character which stored in variable</title>
      <link>https://community.hpe.com/t5/operating-system-linux/echo-pipe-character-which-stored-in-variable/m-p/3606201#M19174</link>
      <description>I might be wrong but can you please try the following.&lt;BR /&gt;&lt;BR /&gt;To see if arguments passed to the script are quoted or not you can insert the following code at the top of the script &lt;BR /&gt;&lt;BR /&gt;i=1&lt;BR /&gt;for arg in "$@"&lt;BR /&gt;do&lt;BR /&gt;        echo "$i: $arg" &amp;gt;&amp;gt; /tmp/test.log&lt;BR /&gt;        ((i=$i+1))&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;If arguments passed to the script were quoted you will see everything on one line&lt;BR /&gt;&lt;BR /&gt;1: rdo ls -l /tmp | grep new&lt;BR /&gt;&lt;BR /&gt;If not, you will see something like&lt;BR /&gt;&lt;BR /&gt;1: rdo&lt;BR /&gt;2: ls&lt;BR /&gt;3: -l&lt;BR /&gt;4: /tmp &lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 18 Aug 2005 21:22:56 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/echo-pipe-character-which-stored-in-variable/m-p/3606201#M19174</guid>
      <dc:creator>Ermin Borovac</dc:creator>
      <dc:date>2005-08-18T21:22:56Z</dc:date>
    </item>
    <item>
      <title>Re: Echo PIPE character which stored in variable</title>
      <link>https://community.hpe.com/t5/operating-system-linux/echo-pipe-character-which-stored-in-variable/m-p/3606202#M19175</link>
      <description>Wow! You are right! The "| grep new" was not printed in the log file. That proved that the "| grep new" was not part of the arg.&lt;BR /&gt;&lt;BR /&gt;By the way, how come the last statement behaves as I expected? (i.e. the "| grep new" is executed).</description>
      <pubDate>Thu, 18 Aug 2005 21:45:20 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/echo-pipe-character-which-stored-in-variable/m-p/3606202#M19175</guid>
      <dc:creator>Eric Leung_2</dc:creator>
      <dc:date>2005-08-18T21:45:20Z</dc:date>
    </item>
    <item>
      <title>Re: Echo PIPE character which stored in variable</title>
      <link>https://community.hpe.com/t5/operating-system-linux/echo-pipe-character-which-stored-in-variable/m-p/3606203#M19176</link>
      <description>Well, if you run it from command line without quotes as&lt;BR /&gt;&lt;BR /&gt;$ ./test.sh rdo ls -l /tmp | grep new&lt;BR /&gt;&lt;BR /&gt;shell first runs './test.sh rdo ls -l /tmp', then it passes the output of that to 'grep new'.&lt;BR /&gt;&lt;BR /&gt;This is probably what happens in your case. Does that clear it up?</description>
      <pubDate>Thu, 18 Aug 2005 21:49:57 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/echo-pipe-character-which-stored-in-variable/m-p/3606203#M19176</guid>
      <dc:creator>Ermin Borovac</dc:creator>
      <dc:date>2005-08-18T21:49:57Z</dc:date>
    </item>
    <item>
      <title>Re: Echo PIPE character which stored in variable</title>
      <link>https://community.hpe.com/t5/operating-system-linux/echo-pipe-character-which-stored-in-variable/m-p/3606204#M19177</link>
      <description>For your information, my C program (rdo.c)is as simple as below:&lt;BR /&gt;&lt;BR /&gt;main(int argc, char *argv[])&lt;BR /&gt;{&lt;BR /&gt;     setuid(0);&lt;BR /&gt;     setgid(0);&lt;BR /&gt;     execvp("/usr/sbin/shell.sh", argv);&lt;BR /&gt;     exit(1);&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;I use it as follow:&lt;BR /&gt;rdo ls -l /tmp | grep new&lt;BR /&gt;&lt;BR /&gt;The output of this command is = "ls -l /tmp/ | grep new"</description>
      <pubDate>Thu, 18 Aug 2005 21:51:59 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/echo-pipe-character-which-stored-in-variable/m-p/3606204#M19177</guid>
      <dc:creator>Eric Leung_2</dc:creator>
      <dc:date>2005-08-18T21:51:59Z</dc:date>
    </item>
    <item>
      <title>Re: Echo PIPE character which stored in variable</title>
      <link>https://community.hpe.com/t5/operating-system-linux/echo-pipe-character-which-stored-in-variable/m-p/3606205#M19178</link>
      <description>I understand the whole situation now.&lt;BR /&gt;&lt;BR /&gt;Thank you very much</description>
      <pubDate>Thu, 18 Aug 2005 21:55:15 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/echo-pipe-character-which-stored-in-variable/m-p/3606205#M19178</guid>
      <dc:creator>Eric Leung_2</dc:creator>
      <dc:date>2005-08-18T21:55:15Z</dc:date>
    </item>
    <item>
      <title>Re: Echo PIPE character which stored in variable</title>
      <link>https://community.hpe.com/t5/operating-system-linux/echo-pipe-character-which-stored-in-variable/m-p/3606206#M19179</link>
      <description>Looking at your C code it looks to me that you have a gigantic security hole on your system. I strongly suggest you look into installing and using sudo.&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://www.courtesan.com/sudo/" target="_blank"&gt;http://www.courtesan.com/sudo/&lt;/A&gt;</description>
      <pubDate>Thu, 18 Aug 2005 22:05:25 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/echo-pipe-character-which-stored-in-variable/m-p/3606206#M19179</guid>
      <dc:creator>Ermin Borovac</dc:creator>
      <dc:date>2005-08-18T22:05:25Z</dc:date>
    </item>
  </channel>
</rss>

