Why does xargs skip first argument when passing to subshell?

elias

Looking for a way to invoke more than one command in a xargs one-liner, I found the recommendation in findutils to invoke the shell from xargs like this:

$ find ... | xargs sh -c 'command $@'

The funny thing is, if I use xargs like that, for some reason it skips the first argument:

$ seq 10 | xargs bash -c 'echo $@'
2 3 4 5 6 7 8 9 10
$ seq 10 | xargs -n2 bash -c 'echo $@'
2
4
6
8
10

Is something wrong with my shell or xargs version? Is that documentation inaccurate?

Using xargs (GNU findutils) 4.4.2 and GNU bash, version 4.3.11(1)-release.

Janis

The [bash] man page says: "-c string If the -c option is present, then commands are read from string. If there are arguments after the string, they are assigned to the positional parameters, starting with $0." - The key is $0; it means that the command name shall be the first argument.

seq 10 | xargs sh -c 'echo $@; echo $0' sh
1 2 3 4 5 6 7 8 9 10
sh

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Why does __new__ method need passing cls argument when called its parent's __new__ across super method?

From Dev

Why does passing a variable by reference not work when invoking a reflective method?

From Dev

Can xargs execute a subshell command for each argument?

From Dev

Why Does Js Slideshow Skip First Two Slides?

From Dev

Why does using the await operator for the second argument to a method affect the value of the first argument?

From Dev

Why does MPMoviePlayerController stutter when first playing?

From Dev

why xargs cannot receive argument

From Dev

Why does passing a method as an argument (&block) not work?

From Dev

Why does using keep_if in Ruby skip over the first element in an array?

From Dev

Bad substitution inside xargs subshell?

From Dev

Why does __new__ method need passing cls argument when called its parent's __new__ across super method?

From Dev

Why does When.js promise.then skip a function?

From Dev

Why does `find` in Linux skip expected results when `-o` is used?

From Dev

How to skip the first argument in a script

From Dev

Passing a list of two PIDs to xargs only kills the first using ssh

From Dev

Why does backbone filter collection fails when passing to view

From Dev

c++: what does this insertion expression do and how does it work when passing as a function argument?

From Dev

Why does here-string argument to echo omit first word?

From Dev

Skip first line from output of each iteration of XARGS

From Dev

Why does the program skip taking input when function is called?

From Dev

Why does using keep_if in Ruby skip over the first element in an array?

From Dev

In "find ... | xargs ...", why does xargs iterate even when find returns zero results?

From Dev

Why the 'xargs' command do not work with figlet but works fine when i run it with 'ls' argument

From Dev

Why does redirection fail when passing through ssh, sudo and sh?

From Dev

How to get variables from subshell while also passing arguments with xargs?

From Dev

First argument is wrong when passing __VA_ARGS__

From Dev

Why does first argument of `Function` deny parentheses?

From Dev

Why does apply skip first element of array used for arguments?

From Dev

Why does a Java while loop that asks for user input using scanner skip the first input

Related Related

  1. 1

    Why does __new__ method need passing cls argument when called its parent's __new__ across super method?

  2. 2

    Why does passing a variable by reference not work when invoking a reflective method?

  3. 3

    Can xargs execute a subshell command for each argument?

  4. 4

    Why Does Js Slideshow Skip First Two Slides?

  5. 5

    Why does using the await operator for the second argument to a method affect the value of the first argument?

  6. 6

    Why does MPMoviePlayerController stutter when first playing?

  7. 7

    why xargs cannot receive argument

  8. 8

    Why does passing a method as an argument (&block) not work?

  9. 9

    Why does using keep_if in Ruby skip over the first element in an array?

  10. 10

    Bad substitution inside xargs subshell?

  11. 11

    Why does __new__ method need passing cls argument when called its parent's __new__ across super method?

  12. 12

    Why does When.js promise.then skip a function?

  13. 13

    Why does `find` in Linux skip expected results when `-o` is used?

  14. 14

    How to skip the first argument in a script

  15. 15

    Passing a list of two PIDs to xargs only kills the first using ssh

  16. 16

    Why does backbone filter collection fails when passing to view

  17. 17

    c++: what does this insertion expression do and how does it work when passing as a function argument?

  18. 18

    Why does here-string argument to echo omit first word?

  19. 19

    Skip first line from output of each iteration of XARGS

  20. 20

    Why does the program skip taking input when function is called?

  21. 21

    Why does using keep_if in Ruby skip over the first element in an array?

  22. 22

    In "find ... | xargs ...", why does xargs iterate even when find returns zero results?

  23. 23

    Why the 'xargs' command do not work with figlet but works fine when i run it with 'ls' argument

  24. 24

    Why does redirection fail when passing through ssh, sudo and sh?

  25. 25

    How to get variables from subshell while also passing arguments with xargs?

  26. 26

    First argument is wrong when passing __VA_ARGS__

  27. 27

    Why does first argument of `Function` deny parentheses?

  28. 28

    Why does apply skip first element of array used for arguments?

  29. 29

    Why does a Java while loop that asks for user input using scanner skip the first input

HotTag

Archive