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.
solaris xargs gnu
add a comment |
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.
solaris xargs gnu
1
Looks like it's the-Ithat'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 1it works as expected. I've tried other characters besides{}as well as the-iflag which assumes{}I won't rule out the-Ibut 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 thisprintf 'onetwothreefour' | gxargs -0 -I{} -n 2 echo "- {}";-)
– mosvy
Nov 30 at 5:42
I'm surprised that-0worked with the OS-suppliedxargs.-0is a non-standard GNU extension toxargs. It's not a POSIX-standard option.
– Andrew Henle
Nov 30 at 10:42
add a comment |
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.
solaris xargs gnu
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
solaris xargs gnu
asked Nov 30 at 5:11
functionvoid
1608
1608
1
Looks like it's the-Ithat'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 1it works as expected. I've tried other characters besides{}as well as the-iflag which assumes{}I won't rule out the-Ibut 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 thisprintf 'onetwothreefour' | gxargs -0 -I{} -n 2 echo "- {}";-)
– mosvy
Nov 30 at 5:42
I'm surprised that-0worked with the OS-suppliedxargs.-0is a non-standard GNU extension toxargs. It's not a POSIX-standard option.
– Andrew Henle
Nov 30 at 10:42
add a comment |
1
Looks like it's the-Ithat'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 1it works as expected. I've tried other characters besides{}as well as the-iflag which assumes{}I won't rule out the-Ibut 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 thisprintf 'onetwothreefour' | gxargs -0 -I{} -n 2 echo "- {}";-)
– mosvy
Nov 30 at 5:42
I'm surprised that-0worked with the OS-suppliedxargs.-0is a non-standard GNU extension toxargs. 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
add a comment |
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-noptions 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.
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-nor the-Ibe 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
add a comment |
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-noptions 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.
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-nor the-Ibe 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
add a comment |
up vote
6
down vote
accepted
You cannot combine the -I and -n options. That's what the standard says:
The
-I,-L, and-noptions 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.
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-nor the-Ibe 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
add a comment |
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-noptions 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.
You cannot combine the -I and -n options. That's what the standard says:
The
-I,-L, and-noptions 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.
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-nor the-Ibe 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
add a comment |
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-nor the-Ibe 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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
1
Looks like it's the
-Ithat'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 1it works as expected. I've tried other characters besides{}as well as the-iflag which assumes{}I won't rule out the-Ibut 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
-0worked with the OS-suppliedxargs.-0is a non-standard GNU extension toxargs. It's not a POSIX-standard option.– Andrew Henle
Nov 30 at 10:42