Metacharacter

From LQWiki
Jump to navigation Jump to search

A metacharacter, in the shell, is a character that usually has some other meaning or is used to signify something other than that character itself. For example, the wildcard * is often a shell metacharacter, and a * is often replaced with (often said to be expanded to or substituted with) a list of all the files in the current directory.

Quoting (or escaping) is done in order to suppress the behaviour of metacharacters. This may be necessary in case you have a filename called a*work or the like, and you do not want the asterisk to be expanded at the command line. Escaping is done with any of the following methods:

  • 'single quotes' (which suppresses all shell substitutions)
  • "double quotes" (which suppresses most substitutions)
  • \backslashes (which escapes single characters)

Example

$ echo ~                                                                  
/home/username

Here the tilde is expanded to the user's home directory.

$ echo \~                                                                 
~

Here the tilde itself is shown