19

When inputting a Google Maps Directions URL into the command line (for opening with Chromium browser via the terminal) there is an ampersand (&) in the URL, however the terminal breaks it there because of Unix stuff being Unix stuff. Is there something I can type into the terminal that when the command actually goes through, that will be treated like an ampersand?

Will ;amp; work?

karel
  • 114,770
Leron
  • 1,660

3 Answers3

22

You need to put the address in quotes:

chromium-browser 'http://whatever.com/?x=1&y=2'
htorque
  • 64,798
  • Okay, I had the quote on the end, but not the one up front... that explains it. Thank you. – Leron Jun 28 '11 at 06:24
10

Quotes will fix this but you can also escape things with a back-slash:

echo http://whatever.com/?x=1\&y=2

Not saying this is better, by any means, it's just another option for situations like this.

Oli
  • 293,335
1

It won't actually matter in this case, but there is a difference between single quotes and double quotes.

Double quotes will substitute special characters such as '$' and quotes, whereas single quotes treat everything literally, except for the closing single quote.

Both will group the text together, which causes chromium to treat it a single argument, and characters like ";#&" have no special meaning in that context.

This shows the use of '\' to escape a double quote within double quotes, and a backslash itself:

mat@sen:~$ echo "a&bc\\#de\"f"
a&bc\#de"f

With single quotes nothing changes:

mat@sen:~$ echo 'a&bc\\#de\"f'
a&bc\\#de\"f

Without the quotes the '&' splits it into two commands:

mat@sen:~$ echo a&bc\\#de\"f
[1] 2619
a
bc\#de"f: command not found
[1]+  Done                    echo a
[1]+  Done                    echo a

Usually when dealing with one kind of quote you can just wrap it in the other type, but you may run into problems with this:

mat@sen:~$ echo "'a'bc$foo"
'a'bc

The single quotes aren't substituted, but the '$' is. The following syntax works though:

mat@sen:~$ echo $'a\'bc$foo'
a'bc$foo
Mat
  • 73