xargs

What am I doing wrong in this bash function?

I'm trying to create a function that goes to a specific directory, and if a single argument is specified add that to the directory string. But no matter what I try I can't get it to work and bash always reports that X is not a directory even though if I copy/paste it to a new command line it works from there. function projects () { DI...

xargs with multiple arguments

I have a source input, input.txt a.txt b.txt c.txt I want to feed these input into a program as the following: my-program --file=a.txt --file=b.txt --file=c.txt So I try to use xargs, but with no luck. cat input.txt | xargs -i echo "my-program --file"{} It gives my-program --file=a.txt my-program --file=b.txt my-program --file=...

Use bash-type `${i%.mp3}` syntax with xargs?

Example of usage (contrived!): rename .mp3 files to .txt. I'd like to be able to do something like find -name '*.mp3' -print0 | xargs -0 -I'file' mv file ${file%.mp3}.txt This doesn't work, so I've resorted to piping find's output through sed -e 's/.mp3//g', which does the trick. Seems a bit hackish though; is there a way to use the...

Is it possible to get the segment number in an xargs invocation

Xargs can be used to cut up the contents of standard input into manageable pieces and invoke a command on each such piece. But is it possible to know which piece it is ? To give an example: seq 1 10 | xargs -P 2 -n 2 mycommand will call mycommand 1 2 & mycommand 3 4 & mycommand 5 6 & mycommand 7 8 & mycommand 9 10 & But I would like...