Home > database >  Pass parameter from list in file
Pass parameter from list in file

Time:05-17

i'm struggling with this topic: I've a file with a list of IDs, something like this:

34
23
478
12579
342356

On the other side, i've a command that i want to run, to show me the details for each object of the list (no much to say on this, is a specific command coming actually from a API). It looks like this, where "id" rappresents a single integer, which must exist in the previous list.

command-to-get-details str id

My idea was to loop in the first file with read, store the IDs in a variable through readarrayand pass them to the second command in a while loop. The problem with this solution is that i can't use readarray in this machine.

Is there any other solution to do this?

Thank you very much

CodePudding user response:

From https://mywiki.wooledge.org/BashFAQ/001

#!/bin/bash

while IFS= read -r id
do
    echo "command-o-get-details str $id"
done < "ids.txt"

Remove the echo to use your specific command.

  • Related