LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   xargs --replace or -I options (https://www.linuxquestions.org/questions/linux-newbie-8/xargs-replace-or-i-options-4175422800/)

zsh 08-18-2012 02:16 PM

xargs --replace or -I options
 
Where is a wrong?
Code:

xargs -I{} foo {} bar/$(basename {})
Instead of the substitution
Code:

$(basename /full/path)
it seems to that basename applied to {}

Thanks!

David the H. 08-18-2012 02:27 PM

"$()" is not a system command, but a shell syntax pattern that runs the command in a subshell. xargs is not a shell, so it cannot execute it. It should be possible by having it execute "bash" or another shell, with the code as the argument to that.

BTW, it may help if you provided more details about what you are trying to do, such as what the input to this command should be, and/or what you want to get out of it.

zsh 08-18-2012 04:17 PM

I tried to form arguments of the command convert from imagemagick package in this way

Code:

find somedir ... | xargs -I{}  convert {}  -resize 50% destdir/$(basename {})
Now to avoid error I refused from direct transfer from find to xargs via pipe

Solution looks like
Code:

list=$(find ...)
for i in $list
do
  convert $i -resize 50% destdir/$(basename $i)
done

Thanks for the help


All times are GMT -5. The time now is 03:04 AM.