What are metacharacters in Linux
The basic structure (according to widespread syntax) of a command should look like this:
|Command name [options] [arguments ...]|
Options are introduced with "-" and usually consist of just one letter. Several options can be grouped:
Any number of arguments can be passed to the command. Most of the time options and arguments can be exchanged in their order.
The leading minus to the introduction of options is, according to the Unix98 standard. Some commands (like ps, tar, ...) also use options after the BSD syntax, after which no leading minus is prescribed:
The GNU rules for long options, which are introduced by two leading minus signs.
|user @ sun> ps --sort tty|
Before a command is executed, bash interprets the command line passed to it. The shell parses the input and searches for characters (strings) with special meanings. Bash then tries to substitute these strings. The order in which the arguments are viewed plays a major role in understanding how Bash works.
In the section Shells, Bash the interested reader will find a detailed discussion on parsing the command line. The examples here are limited to the essentials, which should, however, already cover the everyday life of most Linux users.
Metacharacters are those special characters in a shell that are used as placeholders for character patterns.
In Bash, the following special characters stand for:
Any character exactly
Any number of characters (including 0)
One of the characters
None of the characters specified
All characters from the range
Stands for the home directory
Cancels the special meaning of the following character
Removes the special meaning of spaces and tabs from the enclosed string (the string is saved as a a Word considered)
Removes any special meanings from the enclosed string
A metacharacter is never interpreted by the respective command, but always by the shell. Because of this, a command like
|user @ sun> cp * .x * .y|
not under a Unix shell.
How Bash works can be illustrated using examples:
|user @ sun> ls /boot/*.map|
The asterisk "*" stands for any number of characters. This means that in the above entry, Bash replaces the entry with all file names that are in the / boot directory and end in ".map".
|user @ sun> ls -d /? [abc] *|
/ sbin / var
The bash replaces the input with all file names from the root directory, the first character of which is arbitrary (?), whose second letter is either an "a", a "b" or a "c", followed by any number (including 0) of any characters "*". The "-d" option of the "ls" command means that only their names are listed for directories, not their contents.
|user @ sun> ls /? [abc] *|
SuSEconfig fsck.minix ldconfig rmmod
YaST genksyms lilo route ...
X11R6 cron lock named spool texfonts
adm games log openwin squid tmp
... without the "-d" option, the output can quickly become confusing.
|user @ sonne> echo "Welcome $ USER"|
user @ sonne> echo 'Welcome $ USER'
Welcome $ USER
USER is a predefined shell variable that contains the user ID of the logged on user. If the argument of echo "quoted" with double quotes means that the space is ignored, but not that $-Character that shows the content of the variable here USER retrieves.
When enclosed in single quotation marks, the special meaning of each character is canceled, including the variable substitution it contains.
- How can I use knowledge management
- Can a student build a drone camera?
- What makes mentoring successful?
- How do I integrate x 1 sinx
- Is the SE ranking or SEMRush better
- Who is Billie Eilish's favorite singer
- You can use Quora
- How to Learn Krishnamurthy Paddathi Astrology
- Will there be more Futurama
- Where do the Death Eaters live
- Is punk anti-nationalist
- Who invented the fog of war
- Why is the Domain Symbolics com famous
- Is there a future in event management
- Are Turkish genes similar to Arab genes
- Who is Liu Xiaobo
- What makes people be dominant
- Is cube steak tender
- Are you a Corbynite
- Airtel Unlimited Postpaid Plan 2999
- What is a phone's WhatsApp number
- Which is stopping you from helping the less fortunate
- How is your trip to China
- May girl purpose to her boyfriend