What are shell metacharacters like \ and >?

Posted on 2007-07-23
Medium Priority
Last Modified: 2008-01-09
What are shell metacharacters like \ and >?
Question by:naseeam

Assisted Solution

ezaton earned 480 total points
ID: 19552703
Add backslash before the characters to use them, if that is what you mean. Example:
$ ls | grep file

$ rm \\file

Same goes for other special characters.
LVL 11

Accepted Solution

avizit earned 560 total points
ID: 19552836
'\' metacharacter gives special meaning to the next character
for example  a  "." ( dot) in a regular expression can mean any character but when preceded by a \ it means a literal dot .

>  redirects the standard output to a file .. say if you had a c program named test which had printfs
then typing

test > outfile
would print the output to the outfile instead of  the console

more metacharacters here

LVL 48

Assisted Solution

Tintin earned 480 total points
ID: 19552862
1.  The backslash means that the next character should be used literally if it is a metacharacter.

2.  > is for redirection to a file

3.  ? is used by the shell to match a single character (similar to . in regex).  Remember that shell globs use some different characters to regexes for matching characters.
LVL 48

Assisted Solution

hernst42 earned 480 total points
ID: 19553810
from man bash:
              A character that, when unquoted, separates words.  One of the following:
              |  & ; ( ) < > space tab
       control operator
              A token that performs a control function.  It is one of the following symbols:
              || & && ; ;; ( ) | <newline>

       Quoting is used to remove the special meaning of certain characters or words to the shell.  Quoting can be used  to  disable  special  treatment  for special characters, to prevent reserved words from being recognized as such, and to prevent parameter expansion.

       Each of the metacharacters listed above under DEFINITIONS has special meaning to the shell and must be quoted if it is to represent itself.

       When  the command history expansion facilities are being used, the history expansion character, usually !, must be quoted to prevent history expansion.

       There are three quoting mechanisms: the escape character, single quotes, and double quotes.

So the \ itself is no metacharacter for the shell, its just a quoting mechanism.

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses
Course of the Month15 days, 4 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question