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.

For some weird reason, I tried "'" as word separator in identifiers, as in:

$ export foo'bar=1
> 
> ^C
$ 

The result is as shown above, id est the prompt changes to ">" and the system obviously waits for more information on my part. As you see, I had to ctrl-C to escape. The same happens using other commands such as

$ ls foo'bar
$ mkdir foo'bar

I'm curious about the sense of all this, that is what special meaning "'" has in terminal commands (so special in fact that it is taken apart even inside ids).

Extra: As an aside I would also like to know the set of special or otherwise invalid characters in file and folder names, both under Unix-like and Windows systems (to get the common subset of safe ones) (in particular, what about all non-ASCII?).

Thank you, Denis

share|improve this question
    
In the Linux world, all characters except for \0 (null) and / are permitted. However, that doesn't mean they're all advisable. Many people consider it best to avoid characters that have a special meaning to the shell. If you want to know about Windows, consult a Windows reference. –  Scott Severance Dec 18 '12 at 5:42

2 Answers 2

The ' character is a very powerful character whenever used in any shell command. Basically the ' (apostrophe marks) disables all kinds of transformations or modifications. It would consider whatever is enclosed with the ' marks as a single entity i.e. a single parameter. Absolutely no sort of substitution or expansion would take place.

Example:

 $ echo '$HOME'

would produce at the output the string $HOME itself and would not print the path to your home directory. Since the single quotes prevents any sort of expansion, substitution and simple considers whatever to be present as a simple parameter in itself.

If you want to use the apostrophe as it is, you have to escape it:

 $ mkdir foo\'bar

 $ cd foo\'bar

If it is not escaped, it will wait for it's pair to be closed, like it happened in your first example.

So, corrected, your command will be:

 $ export foo\'bar=1

NOTE: As Milan Todorovic noticed, this will not be valid, because you cannot use apostrophe in this case.

share|improve this answer
1  
Thank you, Frantique, that's all what I needed. Denis –  denis 63 Dec 17 '12 at 16:36
    
You are welcome. –  Frantique Dec 18 '12 at 8:31
1  
@denis63 please accept the answer if it is what you needed to see :) –  Rinzwind Feb 5 '13 at 10:55

Character ' is a special character. You use it to mark part of command line entry that won't be changed (e.g. no replacement for wildcards). For example:

$ ls 'bla*'
ls: cannot access bla*: No such file or directory

This means that argument for ls was bla* and not everything that begins with bla.

The reason why you get > character is because you must use one ' for opening and one ' for closing part that won't be changed.

If you want to use ' in folder names you must escape it like this: \'. So if you want to list folder named foo'bar you should type ls foo\'bar.

Oh, and I'm not sure if it is possible to use ' in environment variable names. I think that you cannot use export foo\'bar=1,

Hope this helps.

share|improve this answer
    
Upvote for your observation about environment variable name restriction. –  Frantique Dec 17 '12 at 15:04
    
Can't upvote yet (new to askubuntu), but the feeling is there. Checked about env var names, it's just as you say. (I feel a bit stupid not to have thought at opening/closing delimiters myself, but I then considered "'" as a real apostrophe, not single-quote). Denis –  denis 63 Dec 17 '12 at 16:40

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.