linux怎么输入符号,linux 输入控制台下输入特殊符号

Shell special characters (metacharacters)

Normally, these characters have special meaning to the shell:

/ ' " ' < > | ; ( ) [ ] ? # $ ^ & * =

Here is the meaning of some of them:

/ ' " and ' are used for quoting and were described before.

< and > are used for input/output redirection and were described before.

| pipes the output of the command to the left of the pipe symbol "|" to the input of the command on the right of the pipe symbol.

; separates multiple commands written on a single line.

and separate the command words.

completes a command or set of commands.

( ) enclose command(s) to be launched in a separate shell (subshell). E.g. ( dir ).

{ } enclose a group of commands to be launched by the current shell. E.g. { dir }. It needs the spaces.

& causes the preceding command to execute in the background (i.e., asynchronously, as its own separate process) so that the next command does not wait for its completion.

* when a filename is expected, it matches any filename except those starting with a dot (or any part of a filename, except the initial dot).

? when a filename is expected, it matches any single character.

[ ] when a filename is expected, it maches any single character enclosed inside the pair of [ ].

&& is an "AND" connecting two commands. command1 && command2 will execute command2 only if command1 exits with the exit status 0 (no error). For example: cat file1 &&

|| is an "OR" connecting two commands. command1 || command2 will execute command2 only if command1 exits with the exit status of non-zero (with an error). For example: cat file1 || cat file2 will display file2 only if displaying file1 didn't succeed.

= assigns a value to a variable. Example. The command:

me=blahblah

assigns the value "blahblah" to the variable called "me". I can print the name of the variable using:

echo $me

$ preceeds the name of a variable to be expanded. The variables are either assigned using "=" or are one of the pre-defined variables (which cannot be assigned to):

$0 name of the shell or the shell script being executed.

$# number of the positional parameters to the command

$1 the value of the first positional parameter passed to the command. $2 is the second positional parameter passed to the command.

etc. up to $9.

$* expands to all positional parameters passed to the command

$@ expands to all positional parameters passed to the command, but individually quoted when "$@" is used.

See man bash if you really need more.

Normally, these characters are special to the shell:

/ ' " ' < > [ ] ? | ; # $ ^ & * ( ) =

There are four different types of quotes: backslash (/), single quotes (apostrophes, '), double quotes (quotation marks, "), and backquotes (').

The backslash / means: disable the special meaning of the subsequent character.

Quoting with '' (two apostrophes) means: quote exactly, disabling any special characters inside the quotes.

Quoting with "" means: disable the special characters inside the quotes except for $ ' /

The pair '' (two backquotes) means: do a command substitution inside the backquotes first.

So what is inside the backquotes is executed by the shell first, and then the output is passed to the command outside the quotes. The same can also be acomplished with $(command) which nests better than backquotes.

Examples. I can create a funny directory called "*" by either / quoting or '' quoting:

mkdir /*

mkdir '*'

This hides the special meaning of the "*" from the shell (without the quote it would mean "all files in the current directory").

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值