Why does `xargs -n ` on SmartOS (SunOS) behave differently than other implementations?











up vote
1
down vote

favorite












It seems the -n option on the xargs found in SmartOS (and I assume Solaris) does not behave like any other version of xargs I've encountered.



Take this example:



Builtin /usr/bin/xargs (odd behavoir):



# printf 'onetwothree' | xargs -0 -I{} -n 1 echo "- {}"
- {} one
- {} two
- {} three


GNU Findutils /opt/local/bin/xargs (expected behavoir):



# printf 'onetwothree' | /opt/local/bin/xargs -0 -I{} -n 1 echo "- {}"
- one
- two
- three


Xargs from MacOS, NetBSD, and CentOS all behave the same as the last example. What's different about the SmartOS xargs?



From the SmartOS xargs manpage:



   -n number
Invokes utility using as many standard input arguments
as possible, up to number (a positive decimal integer)
arguments maximum. Fewer arguments are used if:

o The command line length accumulated exceeds
the size specified by the -s option (or
{LINE_MAX} if there is no -s option), or

o The last iteration has fewer than number, but
not zero, operands remaining.


From the Gnu Findutils xargs manpage:



   -n max-args, --max-args=max-args
Use at most max-args arguments per command line. Fewer than max-args arguments will be used if the size (see the -s option) is exceeded, un‐
less the -x option is given, in which case xargs will exit.


I discovered this difference while porting a shell script and I'm curious if anyone knows why the behavoir is different.










share|improve this question


















  • 1




    Looks like it's the -I that's behaving differently (not doing anything on SnartOS), not the -n.
    – n.st
    Nov 30 at 5:15












  • That was my thought as well, but if I remove -n 1 it works as expected. I've tried other characters besides {} as well as the -i flag which assumes {} I won't rule out the -I but I don't know how else to try it.
    – functionvoid
    Nov 30 at 5:28












  • What happens with those other placeholders?
    – n.st
    Nov 30 at 5:30










  • If you want to see that GNU xargs behavior is not always the one expected, try this printf 'onetwothreefour' | gxargs -0 -I{} -n 2 echo "- {}" ;-)
    – mosvy
    Nov 30 at 5:42










  • I'm surprised that -0 worked with the OS-supplied xargs. -0 is a non-standard GNU extension to xargs. It's not a POSIX-standard option.
    – Andrew Henle
    Nov 30 at 10:42

















up vote
1
down vote

favorite












It seems the -n option on the xargs found in SmartOS (and I assume Solaris) does not behave like any other version of xargs I've encountered.



Take this example:



Builtin /usr/bin/xargs (odd behavoir):



# printf 'onetwothree' | xargs -0 -I{} -n 1 echo "- {}"
- {} one
- {} two
- {} three


GNU Findutils /opt/local/bin/xargs (expected behavoir):



# printf 'onetwothree' | /opt/local/bin/xargs -0 -I{} -n 1 echo "- {}"
- one
- two
- three


Xargs from MacOS, NetBSD, and CentOS all behave the same as the last example. What's different about the SmartOS xargs?



From the SmartOS xargs manpage:



   -n number
Invokes utility using as many standard input arguments
as possible, up to number (a positive decimal integer)
arguments maximum. Fewer arguments are used if:

o The command line length accumulated exceeds
the size specified by the -s option (or
{LINE_MAX} if there is no -s option), or

o The last iteration has fewer than number, but
not zero, operands remaining.


From the Gnu Findutils xargs manpage:



   -n max-args, --max-args=max-args
Use at most max-args arguments per command line. Fewer than max-args arguments will be used if the size (see the -s option) is exceeded, un‐
less the -x option is given, in which case xargs will exit.


I discovered this difference while porting a shell script and I'm curious if anyone knows why the behavoir is different.










share|improve this question


















  • 1




    Looks like it's the -I that's behaving differently (not doing anything on SnartOS), not the -n.
    – n.st
    Nov 30 at 5:15












  • That was my thought as well, but if I remove -n 1 it works as expected. I've tried other characters besides {} as well as the -i flag which assumes {} I won't rule out the -I but I don't know how else to try it.
    – functionvoid
    Nov 30 at 5:28












  • What happens with those other placeholders?
    – n.st
    Nov 30 at 5:30










  • If you want to see that GNU xargs behavior is not always the one expected, try this printf 'onetwothreefour' | gxargs -0 -I{} -n 2 echo "- {}" ;-)
    – mosvy
    Nov 30 at 5:42










  • I'm surprised that -0 worked with the OS-supplied xargs. -0 is a non-standard GNU extension to xargs. It's not a POSIX-standard option.
    – Andrew Henle
    Nov 30 at 10:42















up vote
1
down vote

favorite









up vote
1
down vote

favorite











It seems the -n option on the xargs found in SmartOS (and I assume Solaris) does not behave like any other version of xargs I've encountered.



Take this example:



Builtin /usr/bin/xargs (odd behavoir):



# printf 'onetwothree' | xargs -0 -I{} -n 1 echo "- {}"
- {} one
- {} two
- {} three


GNU Findutils /opt/local/bin/xargs (expected behavoir):



# printf 'onetwothree' | /opt/local/bin/xargs -0 -I{} -n 1 echo "- {}"
- one
- two
- three


Xargs from MacOS, NetBSD, and CentOS all behave the same as the last example. What's different about the SmartOS xargs?



From the SmartOS xargs manpage:



   -n number
Invokes utility using as many standard input arguments
as possible, up to number (a positive decimal integer)
arguments maximum. Fewer arguments are used if:

o The command line length accumulated exceeds
the size specified by the -s option (or
{LINE_MAX} if there is no -s option), or

o The last iteration has fewer than number, but
not zero, operands remaining.


From the Gnu Findutils xargs manpage:



   -n max-args, --max-args=max-args
Use at most max-args arguments per command line. Fewer than max-args arguments will be used if the size (see the -s option) is exceeded, un‐
less the -x option is given, in which case xargs will exit.


I discovered this difference while porting a shell script and I'm curious if anyone knows why the behavoir is different.










share|improve this question













It seems the -n option on the xargs found in SmartOS (and I assume Solaris) does not behave like any other version of xargs I've encountered.



Take this example:



Builtin /usr/bin/xargs (odd behavoir):



# printf 'onetwothree' | xargs -0 -I{} -n 1 echo "- {}"
- {} one
- {} two
- {} three


GNU Findutils /opt/local/bin/xargs (expected behavoir):



# printf 'onetwothree' | /opt/local/bin/xargs -0 -I{} -n 1 echo "- {}"
- one
- two
- three


Xargs from MacOS, NetBSD, and CentOS all behave the same as the last example. What's different about the SmartOS xargs?



From the SmartOS xargs manpage:



   -n number
Invokes utility using as many standard input arguments
as possible, up to number (a positive decimal integer)
arguments maximum. Fewer arguments are used if:

o The command line length accumulated exceeds
the size specified by the -s option (or
{LINE_MAX} if there is no -s option), or

o The last iteration has fewer than number, but
not zero, operands remaining.


From the Gnu Findutils xargs manpage:



   -n max-args, --max-args=max-args
Use at most max-args arguments per command line. Fewer than max-args arguments will be used if the size (see the -s option) is exceeded, un‐
less the -x option is given, in which case xargs will exit.


I discovered this difference while porting a shell script and I'm curious if anyone knows why the behavoir is different.







solaris xargs gnu






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 30 at 5:11









functionvoid

1608




1608








  • 1




    Looks like it's the -I that's behaving differently (not doing anything on SnartOS), not the -n.
    – n.st
    Nov 30 at 5:15












  • That was my thought as well, but if I remove -n 1 it works as expected. I've tried other characters besides {} as well as the -i flag which assumes {} I won't rule out the -I but I don't know how else to try it.
    – functionvoid
    Nov 30 at 5:28












  • What happens with those other placeholders?
    – n.st
    Nov 30 at 5:30










  • If you want to see that GNU xargs behavior is not always the one expected, try this printf 'onetwothreefour' | gxargs -0 -I{} -n 2 echo "- {}" ;-)
    – mosvy
    Nov 30 at 5:42










  • I'm surprised that -0 worked with the OS-supplied xargs. -0 is a non-standard GNU extension to xargs. It's not a POSIX-standard option.
    – Andrew Henle
    Nov 30 at 10:42
















  • 1




    Looks like it's the -I that's behaving differently (not doing anything on SnartOS), not the -n.
    – n.st
    Nov 30 at 5:15












  • That was my thought as well, but if I remove -n 1 it works as expected. I've tried other characters besides {} as well as the -i flag which assumes {} I won't rule out the -I but I don't know how else to try it.
    – functionvoid
    Nov 30 at 5:28












  • What happens with those other placeholders?
    – n.st
    Nov 30 at 5:30










  • If you want to see that GNU xargs behavior is not always the one expected, try this printf 'onetwothreefour' | gxargs -0 -I{} -n 2 echo "- {}" ;-)
    – mosvy
    Nov 30 at 5:42










  • I'm surprised that -0 worked with the OS-supplied xargs. -0 is a non-standard GNU extension to xargs. It's not a POSIX-standard option.
    – Andrew Henle
    Nov 30 at 10:42










1




1




Looks like it's the -I that's behaving differently (not doing anything on SnartOS), not the -n.
– n.st
Nov 30 at 5:15






Looks like it's the -I that's behaving differently (not doing anything on SnartOS), not the -n.
– n.st
Nov 30 at 5:15














That was my thought as well, but if I remove -n 1 it works as expected. I've tried other characters besides {} as well as the -i flag which assumes {} I won't rule out the -I but I don't know how else to try it.
– functionvoid
Nov 30 at 5:28






That was my thought as well, but if I remove -n 1 it works as expected. I've tried other characters besides {} as well as the -i flag which assumes {} I won't rule out the -I but I don't know how else to try it.
– functionvoid
Nov 30 at 5:28














What happens with those other placeholders?
– n.st
Nov 30 at 5:30




What happens with those other placeholders?
– n.st
Nov 30 at 5:30












If you want to see that GNU xargs behavior is not always the one expected, try this printf 'onetwothreefour' | gxargs -0 -I{} -n 2 echo "- {}" ;-)
– mosvy
Nov 30 at 5:42




If you want to see that GNU xargs behavior is not always the one expected, try this printf 'onetwothreefour' | gxargs -0 -I{} -n 2 echo "- {}" ;-)
– mosvy
Nov 30 at 5:42












I'm surprised that -0 worked with the OS-supplied xargs. -0 is a non-standard GNU extension to xargs. It's not a POSIX-standard option.
– Andrew Henle
Nov 30 at 10:42






I'm surprised that -0 worked with the OS-supplied xargs. -0 is a non-standard GNU extension to xargs. It's not a POSIX-standard option.
– Andrew Henle
Nov 30 at 10:42












1 Answer
1






active

oldest

votes

















up vote
6
down vote



accepted










You cannot combine the -I and -n options. That's what the standard says:




The -I, -L, and -n options are mutually-exclusive. Some
implementations use the last one specified if more than one is given
on a command line; other implementations treat combinations of the
options in different ways.




See also this and this.






share|improve this answer























  • That makes sense! Thanks!
    – functionvoid
    Nov 30 at 5:42










  • Your answer would be more complete by indicating which are the correct arguments that should be used in this particular case... Should the -n or the -I be dropped, and why?
    – Filipe Brandenburger
    Nov 30 at 5:57






  • 3




    @FilipeBrandenburger I guess the OP's example was only to illustrate the broken buggy behavior; I've already explained in the linked answer how to insert arguments in the xargs' command at any position without the use of -I. I will not repeat it here, since that wasn't the point of the question.
    – mosvy
    Nov 30 at 6:53











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f485072%2fwhy-does-xargs-n-on-smartos-sunos-behave-differently-than-other-implementa%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
6
down vote



accepted










You cannot combine the -I and -n options. That's what the standard says:




The -I, -L, and -n options are mutually-exclusive. Some
implementations use the last one specified if more than one is given
on a command line; other implementations treat combinations of the
options in different ways.




See also this and this.






share|improve this answer























  • That makes sense! Thanks!
    – functionvoid
    Nov 30 at 5:42










  • Your answer would be more complete by indicating which are the correct arguments that should be used in this particular case... Should the -n or the -I be dropped, and why?
    – Filipe Brandenburger
    Nov 30 at 5:57






  • 3




    @FilipeBrandenburger I guess the OP's example was only to illustrate the broken buggy behavior; I've already explained in the linked answer how to insert arguments in the xargs' command at any position without the use of -I. I will not repeat it here, since that wasn't the point of the question.
    – mosvy
    Nov 30 at 6:53















up vote
6
down vote



accepted










You cannot combine the -I and -n options. That's what the standard says:




The -I, -L, and -n options are mutually-exclusive. Some
implementations use the last one specified if more than one is given
on a command line; other implementations treat combinations of the
options in different ways.




See also this and this.






share|improve this answer























  • That makes sense! Thanks!
    – functionvoid
    Nov 30 at 5:42










  • Your answer would be more complete by indicating which are the correct arguments that should be used in this particular case... Should the -n or the -I be dropped, and why?
    – Filipe Brandenburger
    Nov 30 at 5:57






  • 3




    @FilipeBrandenburger I guess the OP's example was only to illustrate the broken buggy behavior; I've already explained in the linked answer how to insert arguments in the xargs' command at any position without the use of -I. I will not repeat it here, since that wasn't the point of the question.
    – mosvy
    Nov 30 at 6:53













up vote
6
down vote



accepted







up vote
6
down vote



accepted






You cannot combine the -I and -n options. That's what the standard says:




The -I, -L, and -n options are mutually-exclusive. Some
implementations use the last one specified if more than one is given
on a command line; other implementations treat combinations of the
options in different ways.




See also this and this.






share|improve this answer














You cannot combine the -I and -n options. That's what the standard says:




The -I, -L, and -n options are mutually-exclusive. Some
implementations use the last one specified if more than one is given
on a command line; other implementations treat combinations of the
options in different ways.




See also this and this.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 30 at 5:35

























answered Nov 30 at 5:29









mosvy

5,1791323




5,1791323












  • That makes sense! Thanks!
    – functionvoid
    Nov 30 at 5:42










  • Your answer would be more complete by indicating which are the correct arguments that should be used in this particular case... Should the -n or the -I be dropped, and why?
    – Filipe Brandenburger
    Nov 30 at 5:57






  • 3




    @FilipeBrandenburger I guess the OP's example was only to illustrate the broken buggy behavior; I've already explained in the linked answer how to insert arguments in the xargs' command at any position without the use of -I. I will not repeat it here, since that wasn't the point of the question.
    – mosvy
    Nov 30 at 6:53


















  • That makes sense! Thanks!
    – functionvoid
    Nov 30 at 5:42










  • Your answer would be more complete by indicating which are the correct arguments that should be used in this particular case... Should the -n or the -I be dropped, and why?
    – Filipe Brandenburger
    Nov 30 at 5:57






  • 3




    @FilipeBrandenburger I guess the OP's example was only to illustrate the broken buggy behavior; I've already explained in the linked answer how to insert arguments in the xargs' command at any position without the use of -I. I will not repeat it here, since that wasn't the point of the question.
    – mosvy
    Nov 30 at 6:53
















That makes sense! Thanks!
– functionvoid
Nov 30 at 5:42




That makes sense! Thanks!
– functionvoid
Nov 30 at 5:42












Your answer would be more complete by indicating which are the correct arguments that should be used in this particular case... Should the -n or the -I be dropped, and why?
– Filipe Brandenburger
Nov 30 at 5:57




Your answer would be more complete by indicating which are the correct arguments that should be used in this particular case... Should the -n or the -I be dropped, and why?
– Filipe Brandenburger
Nov 30 at 5:57




3




3




@FilipeBrandenburger I guess the OP's example was only to illustrate the broken buggy behavior; I've already explained in the linked answer how to insert arguments in the xargs' command at any position without the use of -I. I will not repeat it here, since that wasn't the point of the question.
– mosvy
Nov 30 at 6:53




@FilipeBrandenburger I guess the OP's example was only to illustrate the broken buggy behavior; I've already explained in the linked answer how to insert arguments in the xargs' command at any position without the use of -I. I will not repeat it here, since that wasn't the point of the question.
– mosvy
Nov 30 at 6:53


















draft saved

draft discarded




















































Thanks for contributing an answer to Unix & Linux Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f485072%2fwhy-does-xargs-n-on-smartos-sunos-behave-differently-than-other-implementa%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

List directoties down one level, excluding some named directories and files

list processes belonging to a network namespace

list systemd RuntimeDirectory mounts