Sign up ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Why does an ampersand in URL cause failure of the following command?

I want to open a web page by running Safari in Terminal, placing the URL as an argument.

This works as expected:

open -a safari ""

But once the quotes being removed, it wouldn't work as expected:

open -a safari

Instead, it returns:

[3] 5395
[4] 5396
[1]   Done                    open -a safari
[2]   Done                    searchOption=all

Seems like ampersand in the URL was treated as "running previous command in the background", though there is no space following the ampersand in the URL.

share|improve this question

1 Answer 1

up vote 2 down vote accepted

The ampersand is a command delimiter (similar to the semicolon ;), but indicates that the command is to be run in the background.

If a command is terminated by the control operator &, the shell executes the command in the background in a subshell. The shell does not wait for the command to finish, and the return status is 0. Commands separated by a ; are executed sequentially; the shell waits for each command to terminate in turn. The return status is the exit status of the last command executed

Therefore you ran three commands:

  • open -a safari " in the background
  • searchOption=all in the background
  • query=good in the foreground

The latter two are simply variable assignments, so no error was displayed (as is often the case when this happens accidentally).

though there is no space following the ampersand in the URL.

This isn't needed for either & or ; to end a command:

$ ls;pwd
Applications Desktop      Documents    Downloads    Library      Movies       Music
Pictures     Projects     Public       Work
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.