Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash command with backticks inside of xargs

Tags:

linux

bash

xargs

  echo $TMPLIST | xargs -I{} -n 1 -P $MAXJOBS curl -o {}_$DATESTRING.dump `get-temp-url --location {}`

$TMPLIST has a list of locations which I want processed. I am trying to run something similar to the above, but the brackets inside of the backticks do not get expanded. What am I doing wrong?

like image 977
pmilb Avatar asked May 08 '15 14:05

pmilb


1 Answers

In this command...

echo $TMPLIST | 
xargs -I{} -n 1 -P $MAXJOBS curl -o {}_$DATESTRING.dump \
  `get-temp-url --location {}`

...the backtics are interpreted by the shell; they are never seen by xargs. You could do something like this:

echo $TMPLIST | 
xargs -I{} -n 1 -P $MAXJOBS \
  sh -c 'curl -o {}_$DATESTRING.dump `get-temp-url --location {}`'

Note that for this to work, DATESTRING will need to be an environment variable, rather than a shell variable (e.g., you would need to export DATESTRING).

like image 179
larsks Avatar answered Nov 03 '22 13:11

larsks