Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

When inputting a Google Maps Directions url into the command line (for opening with chromium browser via 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, it will be treated like an ampersand?

will ;amp; work?

share|improve this question

3 Answers 3

up vote 10 down vote accepted

You need to put the address in quotes:

chromium-browser 'http://whatever.com/?x=1&y=2'
share|improve this answer
    
Okay, I had the quote on the end, but not the one up front... that explains it. Thank you. –  Leron Jun 28 '11 at 6:24

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.

share|improve this answer

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
share|improve this answer

Your Answer

 
discard

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.