search
HomeOperation and MaintenanceLinux Operation and MaintenanceSummary of commonly used special characters in bash

#Comment symbol (Hashmark)

1. At the beginning of the line of the shell file, as the shell call interpreter mark, #!/bin/bash;

2. Used as a comment in the configuration file. In a line, the content after # will not be executed.

;

is used as the separator for multiple commands (Command separator [semicolon]).

When multiple commands are to be placed on the same line, they can be separated by semicolons.

;;

Continuous semicolon (Terminator [double semicolon]).

When using the case option, it is used as the terminator of each option.

.

Dot command.

1. Execute the current directory file

                #!/bin/bash

      .pythontab-file

2. As part of the file name, in the file The beginning of the name indicates that the file is a hidden file

3. As a directory name, one dot represents the current directory, and two dots represent the upper directory (the parent directory of the current directory). Note that more than two dots do not appear unless you surround the dot character itself with quotation marks (single/double);

4. In regular expressions, the dot represents any character.

"

Double quotation marks.

Partial quotation. Content surrounded by double quotation marks allows variable expansion and the existence of escape characters.

'

Single quotation mark (full quoting [single quote]).

All characters enclosed in single quotation marks are treated as the characters themselves,

Comma (comma operator [comma]).

1. Used to connect a series of mathematical expressions. This series of mathematical expressions are evaluated, but only the last evaluation result is returned. For example: ##.

##!/Bin/Bash

Lett1 = (((A = 5+1, B = 7+2))

## Echot1 = $ t1, a = $ a, b, b, b, b =$b

      ##This $t1=$b;

\

Backslash, backslash (escape [backslash]). 1. Placed before the special symbol, the function of escaping the special symbol only represents the special symbol itself, which is commonly used in strings;

2. Placed at the end of a line of instructions, indicating the subsequent carriage return Invalid (in fact, Enter is escaped), the input of subsequent new lines is still regarded as part of the current command

/

slash, slash (Filename path separator [forward slash]). .

1. As the separator of the path, there is only one slash in the path to represent the root directory, and the path starting with the slash represents the path starting from the root directory;

2. As operator, represents the division symbol. For example: a=4/2

`

Backquotes, backquotes (Command substitution[backquotes]). . The enclosed command can be executed and the execution result is assigned to a variable. For example: a=`dirname '/tmp/x.log'`. The result returned by dirname will be assigned to a. Note , here Mitchell specifically uses backticks and single quotes, pay attention to the difference

:

null command [colon]), what is this command? Neither is done, but there is a return value, and the return value is 0 (ie: true). The function of this command is very wonderful.

1. It can be used as a condition for while loop;

##2. Use it as a placeholder in the if branch (that is, when a certain branch does nothing);

3. Place it as a separator where there must be a binary operation, such as: ${username= `whoami`}

4. Assign a value to a string variable in parameter substitution, and truncate the length of a file to 0 in the redirection operation (>) (:>> When used like this, If the target exists, do nothing), this can only be used in ordinary files, not in pipes, symbolic links and other special files;

5. You can even use it to comment (the content after # will not be checked, but the content after : will be checked. If there is a syntax error in the statement, an error will be reported);

6. You can also use it as a domain separator, such as in the environment variable $PATH, Or in passwd, there is a colon as a domain separator;

7. You can also use a colon as a function name, but this will change the original meaning of the colon (if you accidentally use it as a function name, You can use unset -f: to undefine the function).

!

Exclamation mark (reverse (or negate) [bang], [exclamation mark]).

Negate a test result or exit status.

1. Indicates reverse logic, such as the following !=, which means not equal;

2. Indicates negation, such as: ls a[!0-9] #Indicates what follows a It is not a file followed by a number;

3. In different environments, the exclamation mark can also appear in indirect variable references;

4. In the command line, it can be used for historical commands To call the mechanism, you can try !$,!#, or !-3 to see, but be aware that this feature cannot be used in script files (it is disabled).

*

Asterisk (wildcard/arithmetic operator[asterisk]).

1. As a wildcard that matches file name extensions, it can automatically match every file in a given directory;

2. It can be used as a character qualifier in regular expressions to indicate the preceding The matching rules match any number of times;

3. Represents multiplication in arithmetic operations.

**

Double asterisk. In arithmetic operations, it means exponentiation operation.

?

Question mark (test operator/wildcard[Question mark]).

1. Represents conditional testing;

2. Represents C-style ternary operator ((condition?true-result:false-result)) within double brackets;

3. Used in parameter substitution expressions to test whether a variable has a value set;

4. As a wildcard character, used to match file name expansion properties and used to match a single character;

5. In a regular expression, it means matching the previous rule 0 or 1 times.

$

Dollar sign (Variable substitution[Dollar sign]).

1. As the leader of a variable, it is used as a variable replacement, that is, to quote the content of a variable, such as: echo $PATH;

2. In a regular expression, it is defined as the end of the line ( End offline).

${}

Parameter substitution (Variable substitution).

is used to represent variables in strings.

$'...'

Expand the quoted content and execute the escaped content within the single quotation marks (the single quotation marks are originally quoted as they are). In this way, one or Multiple [\] escaped octal, hexadecimal values ​​expanded to ASCII or Unicode characters.

$*

$@

Positional Parameters.

This is used when passing parameters when using script files. Both can return all parameters of the calling script file, but $* returns all parameters as a whole (string), while $@ returns each parameter as a unit as a parameter list. Note that you need to enclose $*, $@ in double quotes when using them. These two variables are affected by $IFS. If used in actual applications, some details should be considered.

$

# represents the number of parameters passed to the script.

$?

When this variable value is used, it returns the exit status code value of the last command, function, or script. If there is no error, it is 0, if it is non-0 , it means that there was an error in the last execution before this.

$$

Process ID variable, this variable saves the process ID value of running the current script.

()

Parenheses (parentheses).

1, Command group. A command enclosed by a set of parentheses is a command group, and the commands in the command group are executed in a subshell. Because it is running in a subshell, there is no way to get the value of the variable inside the brackets outside the brackets, but conversely, within the command group, you can get the outside value. This is a bit like the relationship between local variables and global variables. In implementation, if you encounter the need to cd to a subdirectory and return to the current directory after the operation is completed, you can consider using subshell to handle it;

2. Used for initialization of arrays.

{x,y,z,...}

Brace Expansion.

This expansion can be used to expand the parameter list in the command. The command will match and expand according to the pattern separated by brackets in the list. One thing to note is that there cannot be spaces in this curly brace expansion. If spaces are indeed necessary, they must be escaped or quoted using quotes. Example: echo {a,b,c}-{\ d," e",' f'}

{a..z}

This flower was added in Bash version 3 As an extension of bracket expansion, you can use {A..Z} to represent a list of all characters from A-Z. Mitchell tested this method and it seems that it only applies to A-Z, a-z, and numbers {minimum..max}. way to expand.

{}

Code blocks (curly brackets).

This is an anonymous function, but unlike a function, the variables in the code block can still be accessed after the code block. Note: There needs to be spaces and statements separated inside the curly braces. In addition, in xargs -i, it can also be used as a text placeholder to mark the location of the output text.

{} \;

This {} represents the path name. This is not built-in in the shell. From what I have seen now, it seems that it is only used in the find command. Pay attention to the semicolon at the end. This is the command sequence that ends the -exec option in the find command. When actually using it, it must be escaped to avoid being misunderstood by the shell.

[]

Square brackets.

1. Test representation, Shell will test the expression within []. It should be noted that [] is part of the Shell’s built-in test, rather than using the external command /usr/bin/test Link;

2. In the context of an array, it represents an array element. Fill in the position of the array element in the square brackets to obtain the content of the corresponding position, such as:

1. Array[ 1]=xxx

2. echo${Array[1]};

3. Indicates the range of the character set. In regular expressions, square brackets indicate the characters that can be matched at this position. Set range.

[[]]

Double brackets.

This structure is also a test, testing the expression in [[]] (Shell keyword). This is better than single square brackets in preventing logical errors in scripts. For example, the &&,||, operators can pass the test in a [[]], but not in []. There is no filename expansion or word splitting in [[]], but parameter expansion and command substitution can be used. Filename wildcards and delimiters like whitespace are not used. Note that if octal, hexadecimal, etc. appear here, the shell will automatically perform conversion comparison.

$[...]

The word expression represents integer expansion.

Execute integer expressions inside square brackets. Example:

1. a=3

2. b=7

3. echo$[$a+$b]

4. echo$ [$a*$b]

5. ##The return is 10 and 21

(())

double parentheses.

represents integer expansion.

In the double bracket structure, all expressions can be like C language, such as: a++, b--, etc.

In the double bracket structure, all variables do not need to be prefixed with the "$" symbol.

Double brackets can perform logical operations and four arithmetic operations

The double bracket structure extends for, while, if conditional test operations

Supports multiple expression operations, each expression Use "," to separate

>

&

>&

>>

Redirection.

scriptname >filename redirects the output of scriptname to the file filename, and overwrites the original file if the filename file exists;

command &>filename redirects the standard output (stdout) of command and Standard error (stderr) to the file filename;

command >&2 Redirect the standard output (stdout) of command to the standard error (stderr);

scriptname >>filename Append the output of scriptname (same as >) to the file filename, or create the file if it does not exist. One > indicates that the file will be overwritten if it exists, and created if it does not exist. Two >> indicates that it will be created if it does not exist. If it exists, it will be added to the original one.

[i]filename Open filename The file is used for reading or writing, and i is assigned to the file as its file descriptor (file descriptor). If the file does not exist, it will be created.

Double less then marks (here-document[double less then marks]).

This is also called Here-document and is used to redirect subsequent content to the stdin of the command on the left.

Three less than signs (here-strings). Here-string is similar to Here-document, here-strings syntax: command [args]

\<...>

Word boundary.

This is a special delimiter used in regular expressions to mark word boundaries. For example: the will match there, another, them, etc. If you only want to match the, you can use this word boundary character, \ will only match the.

|

Pipe. Pipes are a concept that exists in both Linux and Unix. It is a very basic and important concept. Its function is to use the output (stdout) produced by the command before the pipe (on the left) as the input (stdin) of the command after the pipe (on the right). For example: ls | wc l, you can use pipes to connect commands together. Note: The standard output of each process in a pipe will be used as the standard input of the next command. The standard output during the period cannot cross the pipe and be used as the standard input of the subsequent command, such as: cat filename | ls -al | sort. Think about the output of this? Also, the pipe runs as a child process, so the pipe cannot cause variables to change.

>|

Force redirection.

This will force overwriting of already existing files.

&

Run job in background[ampersand]).

If the command is followed by an & symbol, the command will run in the background.

&&

||

Logical operator.

In the test structure, these two operators can be used to connect two logical values. || returns 0 (true) when one of the test conditions is true, and false if all are false; && returns true (0) when both test conditions are true, and false if any.

-

Minus sign, hyphen (Hyphen/minus/dash).

1. As an option, the prefix [option, prefix] is used.

2. Source or destination for stdin or stdout redirection [dash]. When tar does not have bunzip2 program patch, we can do this: bunzip2 linux-2.6.13.tar.bz2 | tar xvf - . Use the previously decompressed data as the standard input of tar (a - is used here)

Note: During implementation, if the file name starts with [-], then add this as a directional operation When echoing a variable, an error may occur. At this time, a suitable prefix path should be added to the file to avoid this situation. Similarly, when echoing a variable, if the variable starts with [-], it may also occur. Unexpected results. To be on the safe side, you can use double quotes to quote scalars:

var="-n"

echo$var

var="-n"

echo$var

Try to see what the output is?

Also, this representation method is not built-in in Bash. To achieve this effect, you need to see whether the software you are using supports this operation;

3. Represents the previous Therefore, if you cd to another directory and want to put back the previous path, you can use cd - to achieve the purpose. In fact, the [-] here uses the environment variable $OLDPWD. Note: [-] here is different from the previous point;

4. The minus sign or negative sign is used in arithmetic operations.

=

Equals.

1. When assigning a value to a variable, is there any space on both sides of the equal sign?

2. Appears as a comparison operator in a comparison test. Note here that if it is in square brackets To appear as a comparison, there need to be spaces on both sides of the equal sign.

+

Plus.

1. Arithmetic operator, indicating addition;

2. In a regular expression, it means that the preceding matching rule matches at least once;

3. As an option marker in a command or filter, use + in some commands or built-in commands to enable certain options, and use - to disable;

4. In parameter substitution (parametersubstitution), the + prefix means Substitute value (when the variable is empty, use the value after +)

%

percent sign (modulo[percent sign]).

1. In arithmetic operations, this is the modulus operator, which is the remainder after division of two numbers;

2. In parameter substitution (parametersubstitution), it can be used as a pattern match. Example:

                                                                                                                                                                                                                                                                                      to #       ##Start searching from the right (think about which symbol is from the left?)

      ##Any content between b and 9 (inclusive)

        ##The first one is to find The shortest matching item

        ##The last one is to find the largest matching item (greedy matching?)

~

tilde (Home directory[tilde]).

This is the same as the internal variable $HOME. By default, it indicates the current user's home directory (home directory). This has the same effect as ~/. If the tilde is followed by the user name, it indicates the user's home directory.

^

caret.

1. In regular expressions, as the beginning-of-line position identifier of a line;

2. In parameter substitution (Parametersubstitution), this usage has two ways One caret (${var^}), or two (${var^^}), respectively means the first letter is capitalized, and all capitals means (Bash version >=4).

Blank

Whitespace.

White space not only refers to spaces (spaces), but also includes tabs (tabs), blank lines (blank lines), or a combination of these. It can be used as a function delimiter to separate commands or variables. A blank line will not affect the behavior of the script, so it can be used to plan the script code to increase readability. The built-in special variable $IFS can be used to target certain commands. The input parameters are split, and the default is the whitespace character. If there are whitespace characters in a string or variable, you can use quotes to avoid possible errors.

The above is the detailed content of Summary of commonly used special characters in bash. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
How to prevent data loss and recycling in DebianHow to prevent data loss and recycling in DebianApr 12, 2025 pm 10:33 PM

In Debian systems, preventing data loss and recycling can be achieved through the following methods: Data backup is used to back up the entire system using the tar command: a compressed backup containing the entire system files, configuration files and user data can be created. Incremental backup using rsync command: rsync is a fast and flexible backup tool that supports both local and remote backups, suitable for periodic backups and synchronized files. Use duplicity for encrypted incremental backup: duplicity provides incremental backup with encryption function to ensure the security of backup data. Use C

What is the impact of Debian Apache logs on SEOWhat is the impact of Debian Apache logs on SEOApr 12, 2025 pm 10:30 PM

The DebianApache log records all access requests to the website, including detailed information such as IP address, request type, response status, etc. These logs have the following impacts on SEO: The importance of Apache logs to SEO Monitor website traffic and user behavior: By analyzing Apache access logs, you can understand how users interact with the website, including the pages they visit, the access time, the devices they use, etc. This information helps optimize website content and structure and improve search engine rankings. Identify potential security threats: Access logs can help identify unauthorized

Where to view the logs of Tigervnc in Debian systemWhere to view the logs of Tigervnc in Debian systemApr 12, 2025 pm 10:27 PM

In Debian systems, the log files of the Tigervnc server are usually stored in the .vnc folder in the user's home directory. The log file name is similar to xf:1.log, where xf:1 represents the display number and desktop environment. To view the log, you can use the following method: Method 1: Use the cat command to view the log content directly: cat~/.vnc/xf:1.log Method 2: Use a text editor (such as nano) to open the log file: nano~/.vnc/xf:1.log Please note that xf:1 may vary depending on your system configuration, and you may need to modify the file name according to the actual situation. If xf:1.log is not found, try to find it

How to detect Nginx SSL status on DebianHow to detect Nginx SSL status on DebianApr 12, 2025 pm 10:24 PM

To detect the SSL status of Nginx on the Debian system, you can use the following methods: Use the Nginx command line tool: Open the terminal and enter the following command to check whether the SSL configuration of Nginx is correct: sudonginx-t-c/etc/nginx/nginx.conf This command will test whether the syntax of the Nginx configuration file is correct and will display SSL-related information. View the Nginx status page: If you enable the status module (ngx) in the Nginx configuration

How does Tigervnc perform on DebianHow does Tigervnc perform on DebianApr 12, 2025 pm 10:21 PM

Tigervnc demonstrates excellent performance on Debian systems and is an actively maintained and efficient VNC server, which is very suitable for remote desktop control needs. Its performance advantages are reflected in the following aspects: Tigervnc's performance advantages on Debian. The efficient RFB protocol: Tigervnc is built on the remote frame buffering protocol (RFB), which achieves real-time and smooth remote desktop interaction by efficiently transmitting screen image updates and user input instructions. Robust client-server architecture: The server side runs on the Debian system, responsible for screen sharing and command reception; the client is connected to the server side through the network for remote operation, and the architecture is stable and reliable. Flexible network connection:

How to monitor Nginx SSL performance on DebianHow to monitor Nginx SSL performance on DebianApr 12, 2025 pm 10:18 PM

This article describes how to effectively monitor the SSL performance of Nginx servers on Debian systems. We will use NginxExporter to export Nginx status data to Prometheus and then visually display it through Grafana. Step 1: Configuring Nginx First, we need to enable the stub_status module in the Nginx configuration file to obtain the status information of Nginx. Add the following snippet in your Nginx configuration file (usually located in /etc/nginx/nginx.conf or its include file): location/nginx_status{stub_status

Which operating systems are supported by Tigervnc in DebianWhich operating systems are supported by Tigervnc in DebianApr 12, 2025 pm 10:15 PM

The open source VNC tool Tigervnc is compatible with a wide range of operating systems, including Windows, Linux, and macOS. This article will introduce in detail the application of Tigervnc on the Debian system. Tigervnc is integrated in the application system of Debian system: In the Debian system, Tigervnc is integrated into the system as a VNC server component. Users can start VNC services through command line tools such as vncserver and customize display settings such as resolution and color depth. Cross-platform connection: Tigervnc client supports Windows, Linux, and macOS, which means users can run this from any

How to filter log information in Debian SyslogHow to filter log information in Debian SyslogApr 12, 2025 pm 10:12 PM

Debian system uses Syslog to record system events. This article introduces three methods to filter DebianSyslog log information: Method 1: Use the grep command to filter log files. The grep command can be used to search for specific keywords or patterns in log files. For example, find lines containing "error" in /var/log/syslog: grep'error'/var/log/syslog uses regular expressions and grep options to achieve more precise filtering. Method 2: Use the journalctl command to filter logs systemd to manage logs using journald. journalctl command is used for querying

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.