I have a command that takes domain names as options. I have a long list of domain names to include and so I'd like to automate the parsing of that list of domains into the command.
For example, the simplest usage would be command --option=example-one.com --output=file.ext
. After adding the list of domains the eventual command to execute would look like command --option=example-one.com ... --option=example-99.io --output=file.ext
(where '...' would be 97 more options, shown abbreviated here)
Is this possible to do in Bash and if yes, what's it called please?
Here's what I tried that didn't work so far:
command --option=$(cat domains.txt) --output=file.ext
command "$(while read baddomains ; do echo -n '--option=$baddomains ' ; done < domains.txt)" --output=file.ext
command --option="domains.txt" --output=file.ext
The command while read baddomains ; do echo -n '--option=$baddomains ' ; done < domains.txt > all-options.txt
does output a list of perfectly formatted options into a new file all-options.txt, but I can't understand how to redirect output of the options back into the command, instead of a text file.
The list of domains includes Cyrillic characters, if that matters.
You can build an array with the arguments:
is the most compact way I know.
What you were trying should have been
but it didn’t work for you because you used the wrong quotes in the subshell, and enclosed the whole
$()
in double quotes, so thatcommand
saw the whole as one argument.It doesn’t matter to these commands, but, if they are not properly punycoded, how can they be valid domain names? If they are punycoded, the shell will see no cyrillic characters whatsoever. It will happily process its input correctly in both cases.