简体   繁体   中英

How to use xargs to run command multiple times?

I have a command that can be run once like:

heroku local:run python put_in_db.py --query='ffb557'

What I want to do is take a list of queries, like ["ffb557", "ttr887"] and run the command for each query. I tried running one to start, but get an error:

echo 'ffb557' | xargs heroku local:run python put_in_db.py --query='{}'

put_in_db.py: error: unrecognized arguments: ffb557

Any idea what I'm doing wrong?

Linux:

% ( echo ffb557 ; echo ttr887 ) | xargs -i echo heroku local:run python put_in_db.py --query='{}'
heroku local:run python put_in_db.py --query=ffb557
heroku local:run python put_in_db.py --query=ttr887

Macos & BSD:

% ( echo ffb557 ; echo ttr887 ) | xargs -I % -n 1 echo heroku local:run python put_in_db.py --query='%'
heroku local:run python put_in_db.py --query=ffb557
heroku local:run python put_in_db.py --query=ttr887

Remove the echo to run the commands.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM