Open multiple urls from Terminal

Assuming you’re using the default bash shell:

for fff in $(echo https://one.com/whatever http://two.com/something%20else )
do
    open $fff
done

You don’t necessarily need the $(echo a b c) and could just paste in the words. You can also skip the multiple lines with two semicolons where needed to split the for loop:

for fff in a b c; do echo $fff; done

Just supply all of the URLs you want to open as arguments to a single open command:

open https://www.youtube.com/ https://en.wikipedia.org/wiki/Main_Page

The open command has been written to handle this.

The reason it doesn't work with && is that in shell syntax, && is a delimiter between different commands, not between arguments to the same command. So it was trying to run https://en.wikipedia.org/wiki/Main_Page as a separate command, which doesn't work.

More specifically, && runs the second command only if the first command succeeds. There are a number of command delimiters you can use with different meanings:

cmd1 ; cmd2    # Runs cmd1 and then cmd2 (just as though they were on different lines)
cmd1 & cmd2    # Runs cmd1 and cmd2 simultaneously, with cmd1 in the background
cmd1 | cmd2    # Runs cmd1 and cmd2 simultaneously, with cmd1's output piped to cmd2's input
cmd1 && cmd2    # Runs cmd1, and then if it succeeds runs cmd2
cmd1 || cmd2    # Runs cmd1, and then if it fails runs cmd2