3

I can open one chrome window through

open https://en.wikipedia.org/wiki/Main_Page

I can also open multiple URLs by multiple lines

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

The following won't work though

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

but it works with

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

I want an elegant inline expression like

open ('https://www.youtube.com/','https://en.wikipedia.org/wiki/Main_Page')

How to do that?

1

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
3

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .