<?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: Command line options to xargs in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/command-line-options-to-xargs/m-p/5045138#M433769</link>
    <description>Well, &lt;BR /&gt;&lt;BR /&gt;In looking at this, it seems that it somehow thinks that "-n1" is THE ARGUMENT to the "-i" command.&lt;BR /&gt;&lt;BR /&gt;Look at :&lt;BR /&gt;&amp;gt; ls -1 | xargs -i -n1 echo hello &lt;BR /&gt;hello file1.txt&lt;BR /&gt;hello file2.txt&lt;BR /&gt;...&lt;BR /&gt;&lt;BR /&gt;Meaning that the "{}" is ignored in your test case because the "-i" has something after it that it *thinks* is going to defined as the new definition of the replacement string.&lt;BR /&gt;&lt;BR /&gt;HOWEVER (counter-counter argument), if that's true - look at:&lt;BR /&gt;&amp;gt; ls -1 | xargs -i -n1 echo -n1 &lt;BR /&gt;-n1 file1.txt&lt;BR /&gt;-n1 file2.txt&lt;BR /&gt;...&lt;BR /&gt;&lt;BR /&gt;this means that the "-i" portion thought it was getting redefined as "-n1", but clearly it didn't like using it, maybe because of the standard globber parsing the "-" part as a switch?  Maybe?  &lt;BR /&gt;&lt;BR /&gt;NO (counter-counter-counter): look at:&lt;BR /&gt;&amp;gt; ls -1 | xargs -i bb -n1 echo bb &lt;BR /&gt;xargs: bb not found&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;What?  that's odd, so now I can't even use the the "-i" switch to redefine anything, cept maybe "-n1" which the "redefiner" code likes, but the "command executor" code doesn't.  It doesn't seem to like anything as a "replacement" argument that it is willing to work with.&lt;BR /&gt;&lt;BR /&gt;TDH (that didn't help)&lt;BR /&gt;&lt;BR /&gt;John&lt;BR /&gt;</description>
    <pubDate>Tue, 08 May 2007 15:05:25 GMT</pubDate>
    <dc:creator>TwoProc</dc:creator>
    <dc:date>2007-05-08T15:05:25Z</dc:date>
    <item>
      <title>Command line options to xargs</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/command-line-options-to-xargs/m-p/5045134#M433765</link>
      <description>Can somebody explain why xargs gives erroneous results depending on the order of the command line options and arguments. For example to list the files in a directory:&lt;BR /&gt;&lt;BR /&gt;# ls -1 | xargs -i -n1 echo {} &lt;BR /&gt;{} file1.txt&lt;BR /&gt;{} file2.txt&lt;BR /&gt;{} file3.txt&lt;BR /&gt;{} file4.txt&lt;BR /&gt;{} file5.txt&lt;BR /&gt;&lt;BR /&gt;Output of the above command is correct if the options to xargs are switched i.e.&lt;BR /&gt;&lt;BR /&gt;# ls -1 | xargs -n1 -i echo {}&lt;BR /&gt;file1.txt&lt;BR /&gt;file2.txt&lt;BR /&gt;file3.txt&lt;BR /&gt;file4.txt&lt;BR /&gt;file5.txt&lt;BR /&gt;&lt;BR /&gt;Could someone clarify why this is so?</description>
      <pubDate>Tue, 08 May 2007 13:19:30 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/command-line-options-to-xargs/m-p/5045134#M433765</guid>
      <dc:creator>Sandman!</dc:creator>
      <dc:date>2007-05-08T13:19:30Z</dc:date>
    </item>
    <item>
      <title>Re: Command line options to xargs</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/command-line-options-to-xargs/m-p/5045135#M433766</link>
      <description>Hello,&lt;BR /&gt;What I know is that the -i and the echo option must interact together, if you want to "assume" the {}, then the -i option must be before the echo.&lt;BR /&gt;&lt;BR /&gt;Let's see the following examples ..&lt;BR /&gt;&lt;BR /&gt;root@marco139:/tmp/marco&amp;gt; ls -1 |xargs -i -n 1 -i echo {}&lt;BR /&gt;file1&lt;BR /&gt;file2&lt;BR /&gt;file3&lt;BR /&gt;file4&lt;BR /&gt;file5&lt;BR /&gt;&lt;BR /&gt;root@marco139:/tmp/marco&amp;gt; ls -1 |xargs -i -n 1 -i -n 1 echo {}&lt;BR /&gt;{} file1&lt;BR /&gt;{} file2&lt;BR /&gt;{} file3&lt;BR /&gt;{} file4&lt;BR /&gt;{} file5&lt;BR /&gt;&lt;BR /&gt;Ok.. another think is that you can put more than one -i in the same line, and the only one that really work is the one that is close to the echo or print.&lt;BR /&gt;&lt;BR /&gt;this other 2 examples shows the relation between the -i and the echo ...&lt;BR /&gt;&lt;BR /&gt;-------------------------------------------&lt;BR /&gt;root@marco139:/tmp/marco&amp;gt; ls -1 |xargs -n1 -i echo mar{}co&lt;BR /&gt;marfile1co&lt;BR /&gt;marfile2co&lt;BR /&gt;marfile3co&lt;BR /&gt;marfile4co&lt;BR /&gt;marfile5co&lt;BR /&gt;&lt;BR /&gt;root@marco139:/tmp/marco&amp;gt; ls -1 |xargs -i -n1  echo mar{}co&lt;BR /&gt;mar{}co file1&lt;BR /&gt;mar{}co file2&lt;BR /&gt;mar{}co file3&lt;BR /&gt;mar{}co file4&lt;BR /&gt;mar{}co file5&lt;BR /&gt;&lt;BR /&gt;I hope this helps ...&lt;BR /&gt;&lt;BR /&gt;Marc'o</description>
      <pubDate>Tue, 08 May 2007 14:08:33 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/command-line-options-to-xargs/m-p/5045135#M433766</guid>
      <dc:creator>Marco A.</dc:creator>
      <dc:date>2007-05-08T14:08:33Z</dc:date>
    </item>
    <item>
      <title>Re: Command line options to xargs</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/command-line-options-to-xargs/m-p/5045136#M433767</link>
      <description>That's an interesting puzzle.&lt;BR /&gt;&lt;BR /&gt;The combination of -i and -n1 is redundant, because -i forces the command to be run once per line of input anyway. On the manual page, the description of the options -I and -i is "Insert mode: command is executed for each line from standard input..."&lt;BR /&gt;&lt;BR /&gt;"xargs -i echo {}" produces the correct kind of output, as expected.&lt;BR /&gt;&lt;BR /&gt;"xargs -n1 echo {}" produces output just like your first example.&lt;BR /&gt;&lt;BR /&gt;Apparently the options -i and -n1 override each other: if -n1 is on the command line after -i, it cancels the "insert mode" but makes xargs run the command with one line of input at a time. If -i is after -n1, -i takes effect and -n1 is ignored.&lt;BR /&gt;&lt;BR /&gt;MK</description>
      <pubDate>Tue, 08 May 2007 14:30:37 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/command-line-options-to-xargs/m-p/5045136#M433767</guid>
      <dc:creator>Matti_Kurkela</dc:creator>
      <dc:date>2007-05-08T14:30:37Z</dc:date>
    </item>
    <item>
      <title>Re: Command line options to xargs</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/command-line-options-to-xargs/m-p/5045137#M433768</link>
      <description>That's correct Matti, I believe this is an application bug ...but that's the way I have used that before because that issue.&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;&lt;BR /&gt;Marco</description>
      <pubDate>Tue, 08 May 2007 14:39:27 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/command-line-options-to-xargs/m-p/5045137#M433768</guid>
      <dc:creator>Marco A.</dc:creator>
      <dc:date>2007-05-08T14:39:27Z</dc:date>
    </item>
    <item>
      <title>Re: Command line options to xargs</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/command-line-options-to-xargs/m-p/5045138#M433769</link>
      <description>Well, &lt;BR /&gt;&lt;BR /&gt;In looking at this, it seems that it somehow thinks that "-n1" is THE ARGUMENT to the "-i" command.&lt;BR /&gt;&lt;BR /&gt;Look at :&lt;BR /&gt;&amp;gt; ls -1 | xargs -i -n1 echo hello &lt;BR /&gt;hello file1.txt&lt;BR /&gt;hello file2.txt&lt;BR /&gt;...&lt;BR /&gt;&lt;BR /&gt;Meaning that the "{}" is ignored in your test case because the "-i" has something after it that it *thinks* is going to defined as the new definition of the replacement string.&lt;BR /&gt;&lt;BR /&gt;HOWEVER (counter-counter argument), if that's true - look at:&lt;BR /&gt;&amp;gt; ls -1 | xargs -i -n1 echo -n1 &lt;BR /&gt;-n1 file1.txt&lt;BR /&gt;-n1 file2.txt&lt;BR /&gt;...&lt;BR /&gt;&lt;BR /&gt;this means that the "-i" portion thought it was getting redefined as "-n1", but clearly it didn't like using it, maybe because of the standard globber parsing the "-" part as a switch?  Maybe?  &lt;BR /&gt;&lt;BR /&gt;NO (counter-counter-counter): look at:&lt;BR /&gt;&amp;gt; ls -1 | xargs -i bb -n1 echo bb &lt;BR /&gt;xargs: bb not found&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;What?  that's odd, so now I can't even use the the "-i" switch to redefine anything, cept maybe "-n1" which the "redefiner" code likes, but the "command executor" code doesn't.  It doesn't seem to like anything as a "replacement" argument that it is willing to work with.&lt;BR /&gt;&lt;BR /&gt;TDH (that didn't help)&lt;BR /&gt;&lt;BR /&gt;John&lt;BR /&gt;</description>
      <pubDate>Tue, 08 May 2007 15:05:25 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/command-line-options-to-xargs/m-p/5045138#M433769</guid>
      <dc:creator>TwoProc</dc:creator>
      <dc:date>2007-05-08T15:05:25Z</dc:date>
    </item>
    <item>
      <title>Re: Command line options to xargs</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/command-line-options-to-xargs/m-p/5045139#M433770</link>
      <description>I don't think that they are redundant options otherwise they would give the same output if used independently i.e.&lt;BR /&gt;&lt;BR /&gt;# echo hello world | xargs -i echo {}&lt;BR /&gt;hello world&lt;BR /&gt;&lt;BR /&gt;# echo hello world | xargs -n1 echo   &lt;BR /&gt;hello&lt;BR /&gt;world&lt;BR /&gt;&lt;BR /&gt;And if they are conflicting options then the man page for xargs(1) should reflect that. However it helps to know that others have similar experiences. Thank you for your help.</description>
      <pubDate>Tue, 08 May 2007 15:19:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/command-line-options-to-xargs/m-p/5045139#M433770</guid>
      <dc:creator>Sandman!</dc:creator>
      <dc:date>2007-05-08T15:19:32Z</dc:date>
    </item>
    <item>
      <title>Re: Command line options to xargs</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/command-line-options-to-xargs/m-p/5045140#M433771</link>
      <description>Sandman, you missed one other documented effect of the "insert mode" option:&lt;BR /&gt;&lt;BR /&gt;# echo hello world | xargs -i echo {}&lt;BR /&gt;hello world&lt;BR /&gt;&lt;BR /&gt;The man page says (emphasis mine):&lt;BR /&gt;-I (and -i): Insert mode: command is executed for each line from standard input, _taking the entire line as a single arg_, inserting it in initial-arguments for each occurrence of replstr.&lt;BR /&gt;&lt;BR /&gt;When xargs is not in insert mode, the processing is different:&lt;BR /&gt;&lt;BR /&gt;# echo hello world | xargs -n1 echo&lt;BR /&gt;hello&lt;BR /&gt;world&lt;BR /&gt;&lt;BR /&gt;Again from the man page:&lt;BR /&gt;Arguments read in from standard input are defined to be contiguous strings of characters _delimited by one or more blanks, tabs, or new-lines_; empty lines are always discarded. Spaces and tabs can be embedded as part of an argument if escaped or quoted. &lt;BR /&gt;&lt;BR /&gt;So, the "-i" option actually has three effects:&lt;BR /&gt;&lt;BR /&gt;- it changes the way xargs parses the standard input (whitespace-delimited vs. strictly newline-delimited)&lt;BR /&gt;&lt;BR /&gt;- it makes xargs construct the command differently (which is the primary effect)&lt;BR /&gt;&lt;BR /&gt;- it optionally allows you to specify the string which should be replaced with a line of standard input.&lt;BR /&gt;&lt;BR /&gt;I think you need lawyer-like reading skills to get all this information out of the man page if you don't know what to expect with xargs... but yes, the information _is_ there, that cannot be denied.&lt;BR /&gt;&lt;BR /&gt;John Joubert's first example:&lt;BR /&gt;&amp;gt; ls -1 | xargs -i -n1 echo hello&lt;BR /&gt;hello file1.txt&lt;BR /&gt;hello file2.txt&lt;BR /&gt;&lt;BR /&gt;The actual output is the same if "-i" is removed, so looks like -i is ignored.&lt;BR /&gt;&lt;BR /&gt;If -i would take -n1 as argument, the output should have been:&lt;BR /&gt;hello&lt;BR /&gt;hello&lt;BR /&gt;because with -i, the output must go exactly where indicated and nowhere else. &lt;BR /&gt;&lt;BR /&gt;John's second example:&lt;BR /&gt;&amp;gt; ls -1 | xargs -i -n1 echo -n1&lt;BR /&gt;-n1 file1.txt&lt;BR /&gt;-n1 file2.txt&lt;BR /&gt;&lt;BR /&gt;Again, the -i is ignored and you get commands like "echo -n1 file1.txt" and "echo -n1 file2.txt".&lt;BR /&gt;&lt;BR /&gt;John's third example is curious:&lt;BR /&gt;&amp;gt; ls -1 | xargs -i bb -n1 echo bb&lt;BR /&gt;xargs: bb not found&lt;BR /&gt;&lt;BR /&gt;Xargs probably uses getopt() function to parse the options. (man 3 getopt)&lt;BR /&gt;HP-UX getopt() does not recognize optional arguments to options, so the options themselves and any mandatory arguments to them are parsed first. &lt;BR /&gt;&lt;BR /&gt;If "insert mode" is in effect, the first remaining non-option string may be the string to be replaced, so it will be handled specially. But in the example, -n1 has overridden -i, so "insert mode" is not in effect and the special handling does not happen.&lt;BR /&gt;&lt;BR /&gt;MK</description>
      <pubDate>Wed, 09 May 2007 03:07:27 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/command-line-options-to-xargs/m-p/5045140#M433771</guid>
      <dc:creator>Matti_Kurkela</dc:creator>
      <dc:date>2007-05-09T03:07:27Z</dc:date>
    </item>
    <item>
      <title>Re: Command line options to xargs</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/command-line-options-to-xargs/m-p/5045141#M433772</link>
      <description>Thank you all for the clarification.</description>
      <pubDate>Thu, 10 May 2007 09:28:09 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/command-line-options-to-xargs/m-p/5045141#M433772</guid>
      <dc:creator>Sandman!</dc:creator>
      <dc:date>2007-05-10T09:28:09Z</dc:date>
    </item>
    <item>
      <title>Re: Command line options to xargs</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/command-line-options-to-xargs/m-p/5045142#M433773</link>
      <description>.</description>
      <pubDate>Thu, 10 May 2007 09:28:44 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/command-line-options-to-xargs/m-p/5045142#M433773</guid>
      <dc:creator>Sandman!</dc:creator>
      <dc:date>2007-05-10T09:28:44Z</dc:date>
    </item>
  </channel>
</rss>

