It looks like the open command can't take data from the standard input, so I ended up using something like this.
some_command | xargs -r-I{} open {}
For those who don't know, xargs (with the right arguments) can act like the map method on javascript arrays. So you can imagine the above doing something like this:
xargs can come in handy in a pinch, but it's usually unnecessary and the way it generates arguments can cause some complications. I can't think of a case where xargs would be more appropriate than Command Substitution or a while read loop, e.g.:
open "$(some_commands)"#thus you fully control word-splitting
or
some_commands | \while IFS=read-r line;do#unsetting IFS here prevents word-splitting
some_other_commands "$line"
even_some_more_commands "$line"#vars declared in here are not valid afterwards,#since they are declared inside the pipeline subshell#and its environment does not hoist#This includes $linedone#alternatively, using process substitution:while IFS=read-r line;do
some_other_commands "$line"#variables set here remain valid afterwards#since this while-loop is not in a subshell#thus the last $line will remain set afterwardsdone < <(some_commands)
With process substitution and the mapfile builtin, you can even populate an array and iterate over that:
I used xargs this week.
It looks like the
opencommand can't take data from the standard input, so I ended up using something like this.For those who don't know,
xargs(with the right arguments) can act like themapmethod on javascript arrays. So you can imagine the above doing something like this:xargscan come in handy in a pinch, but it's usually unnecessary and the way it generates arguments can cause some complications. I can't think of a case wherexargswould be more appropriate than Command Substitution or awhile readloop, e.g.:or
With process substitution and the
mapfilebuiltin, you can even populate an array and iterate over that:Nice!