📄 special-chars.html
字号:
></TD></TR></TABLE></DIV></DD><DT><SPANCLASS="TOKEN">-</SPAN></DT><DD><DIVCLASS="FORMALPARA"><P><B>previous working directory. </B>A <BCLASS="COMMAND">cd -</B> command changes to the previous working directory. This uses the <AHREF="variables2.html#OLDPWD">$OLDPWD</A> <AHREF="othertypesv.html#ENVREF">environmental variable</A>.</P></DIV><DIVCLASS="CAUTION"><TABLECLASS="CAUTION"WIDTH="90%"BORDER="0"><TR><TDWIDTH="25"ALIGN="CENTER"VALIGN="TOP"><IMGSRC="common/caution.png"HSPACE="5"ALT="Caution"></TD><TDALIGN="LEFT"VALIGN="TOP"><P>Do not confuse the <SPANCLASS="QUOTE">"-"</SPAN> used in this sense with the <SPANCLASS="QUOTE">"-"</SPAN> redirection operator just discussed. The interpretation of the <SPANCLASS="QUOTE">"-"</SPAN> depends on the context in which it appears.</P></TD></TR></TABLE></DIV></DD><DT><SPANCLASS="TOKEN">-</SPAN></DT><DD><DIVCLASS="FORMALPARA"><P><B>Minus. </B>Minus sign in an <AHREF="operations.html#AROPS1">arithmetic operation</A>.</P></DIV></DD><DT><SPANCLASS="TOKEN">=</SPAN></DT><DD><DIVCLASS="FORMALPARA"><P><B>Equals. </B><AHREF="varassignment.html#EQREF">Assignment operator</A> <TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="PROGRAMLISTING"> 1 a=28 2 echo $a # 28</PRE></TD></TR></TABLE></P></DIV><P>In a <AHREF="comparison-ops.html#EQUALSIGNREF">different context</A>, the <SPANCLASS="QUOTE">"<SPANCLASS="TOKEN">=</SPAN>"</SPAN> is a <AHREF="comparison-ops.html#SCOMPARISON1">string comparison</A> operator.</P></DD><DT><SPANCLASS="TOKEN">+</SPAN></DT><DD><DIVCLASS="FORMALPARA"><P><B>Plus. </B>Addition <AHREF="operations.html#AROPS1">arithmetic operator</A>.</P></DIV><P>In a <AHREF="regexp.html#PLUSREF">different context</A>, the <SPANCLASS="TOKEN">+</SPAN> is a <AHREF="regexp.html">Regular Expression</A> operator.</P></DD><DT><SPANCLASS="TOKEN">+</SPAN></DT><DD><DIVCLASS="FORMALPARA"><P><B>Option. </B>Option flag for a command or filter.</P></DIV><P>Certain commands and <AHREF="internal.html#BUILTINREF">builtins</A> use the <SPANCLASS="TOKEN">+</SPAN> to enable certain options and the <SPANCLASS="TOKEN">-</SPAN> to disable them.</P></DD><DT><SPANCLASS="TOKEN">%</SPAN></DT><DD><DIVCLASS="FORMALPARA"><P><B><AHREF="operations.html#MODULOREF">modulo</A>. </B>Modulo (remainder of a division) <AHREF="operations.html#AROPS1">arithmetic operation</A>.</P></DIV><P>In a <AHREF="parameter-substitution.html#PCTPATREF">different context</A>, the <SPANCLASS="TOKEN">%</SPAN> is a <AHREF="parameter-substitution.html#PSUB2">pattern matching</A> operator.</P></DD><DT><SPANCLASS="TOKEN">~</SPAN></DT><DD><DIVCLASS="FORMALPARA"><P><B>home directory [tilde]. </B>This corresponds to the <AHREF="variables2.html#HOMEDIRREF">$HOME</A> internal variable. <ICLASS="EMPHASIS">~bozo</I> is bozo's home directory, and <BCLASS="COMMAND">ls ~bozo</B> lists the contents of it. <SPANCLASS="TOKEN">~/</SPAN> is the current user's home directory, and <BCLASS="COMMAND">ls ~/</B> lists the contents of it. <TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="SCREEN"> <TTCLASS="PROMPT">bash$ </TT><TTCLASS="USERINPUT"><B>echo ~bozo</B></TT> <TTCLASS="COMPUTEROUTPUT">/home/bozo</TT> <TTCLASS="PROMPT">bash$ </TT><TTCLASS="USERINPUT"><B>echo ~</B></TT> <TTCLASS="COMPUTEROUTPUT">/home/bozo</TT> <TTCLASS="PROMPT">bash$ </TT><TTCLASS="USERINPUT"><B>echo ~/</B></TT> <TTCLASS="COMPUTEROUTPUT">/home/bozo/</TT> <TTCLASS="PROMPT">bash$ </TT><TTCLASS="USERINPUT"><B>echo ~:</B></TT> <TTCLASS="COMPUTEROUTPUT">/home/bozo:</TT> <TTCLASS="PROMPT">bash$ </TT><TTCLASS="USERINPUT"><B>echo ~nonexistent-user</B></TT> <TTCLASS="COMPUTEROUTPUT">~nonexistent-user</TT> </PRE></TD></TR></TABLE> </P></DIV></DD><DT><SPANCLASS="TOKEN">~+</SPAN></DT><DD><DIVCLASS="FORMALPARA"><P><B>current working directory. </B>This corresponds to the <AHREF="variables2.html#PWDREF">$PWD</A> internal variable.</P></DIV></DD><DT><SPANCLASS="TOKEN">~-</SPAN></DT><DD><DIVCLASS="FORMALPARA"><P><B>previous working directory. </B>This corresponds to the <AHREF="variables2.html#OLDPWD">$OLDPWD</A> internal variable.</P></DIV></DD><DT><SPANCLASS="TOKEN">=~</SPAN></DT><DD><DIVCLASS="FORMALPARA"><P><B><AHREF="bashver3.html#REGEXMATCHREF">regular expression match</A>. </B>This operator was introduced with <AHREF="bashver3.html#BASH3REF">version 3</A> of Bash.</P></DIV></DD><DT><SPANCLASS="TOKEN">^</SPAN></DT><DD><DIVCLASS="FORMALPARA"><P><B>beginning-of-line. </B>In a <AHREF="regexp.html#REGEXREF">regular expression</A>, a <SPANCLASS="QUOTE">"^"</SPAN> addresses the beginning of a line of text.</P></DIV></DD><DT>Control Characters</DT><DD><P><ANAME="CONTROLCHARREF"></A></P><DIVCLASS="FORMALPARA"><P><B> change the behavior of the terminal or text display. </B>A control character is a <BCLASS="KEYCAP">CONTROL</B> + <BCLASS="KEYCAP">key</B> combination.</P></DIV><P>Control characters are not normally useful inside a script.</P><UL><LI><P><TTCLASS="USERINPUT"><B>Ctl-B</B></TT></P><P>Backspace (nondestructive).</P></LI><LI><P><TTCLASS="USERINPUT"><B>Ctl-C</B></TT></P><P>Break. Terminate a foreground job.</P></LI><LI><P><ANAME="CTLDREF"></A></P><P><TTCLASS="USERINPUT"><B>Ctl-D</B></TT></P><P>Log out from a shell (similar to <AHREF="exit-status.html#EXITCOMMANDREF">exit</A>).</P><P><SPANCLASS="QUOTE">"EOF"</SPAN> (end of file). This also terminates input from <TTCLASS="FILENAME">stdin</TT>.</P><P>When typing text on the console or in an <ICLASS="FIRSTTERM">xterm</I> window, <TTCLASS="USERINPUT"><B>Ctl-D</B></TT> erases the character under the cursor. When there are no characters present, <TTCLASS="USERINPUT"><B>Ctl-D</B></TT> logs out of the session, as expected. In an xterm window, this has the effect of closing the window.</P></LI><LI><P><TTCLASS="USERINPUT"><B>Ctl-G</B></TT></P><P><SPANCLASS="QUOTE">"BEL"</SPAN> (beep). On some old-time teletype terminals, this would actually ring a bell.</P></LI><LI><P><TTCLASS="USERINPUT"><B>Ctl-H</B></TT></P><P><SPANCLASS="QUOTE">"Rubout"</SPAN> (destructive backspace). Erases characters the cursor backs over while backspacing.</P><P> <TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="PROGRAMLISTING"> 1 #!/bin/bash 2 # Embedding Ctl-H in a string. 3 4 a="^H^H" # Two Ctl-H's (backspaces). 5 echo "abcdef" # abcdef 6 echo -n "abcdef$a " # abcd f 7 # Space at end ^ ^ Backspaces twice. 8 echo -n "abcdef$a" # abcdef 9 # No space at end Doesn't backspace (why?). 10 # Results may not be quite as expected. 11 echo; echo</PRE></TD></TR></TABLE> </P></LI><LI><P><TTCLASS="USERINPUT"><B>Ctl-I</B></TT></P><P>Horizontal tab.</P></LI><LI><P><TTCLASS="USERINPUT"><B>Ctl-J</B></TT></P><P>Newline (line feed). In a script, may also be expressed in octal notation -- '\012' or in hexadecimal -- '\x0a'.</P></LI><LI><P><TTCLASS="USERINPUT"><B>Ctl-K</B></TT></P><P>Vertical tab.</P><P>When typing text on the console or in an <ICLASS="EMPHASIS">xterm</I> window, <TTCLASS="USERINPUT"><B>Ctl-K</B></TT> erases from the character under the cursor to end of line.</P></LI><LI><P><TTCLASS="USERINPUT"><B>Ctl-L</B></TT></P><P>Formfeed (clear the terminal screen). This has the same effect as the <AHREF="terminalccmds.html#CLEARREF">clear</A> command.</P></LI><LI><P><TTCLASS="USERINPUT"><B>Ctl-M</B></TT></P><P>Carriage return.</P><P> <TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="PROGRAMLISTING"> 1 #!/bin/bash 2 # Thank you, Lee Maschmeyer, for this example. 3 4 read -n 1 -s -p $'Control-M leaves cursor at beginning of this line. Press Enter. \x0d' 5 # Of course, '0d' is the hex equivalent of Control-M. 6 echo >&2 # The '-s' makes anything typed silent, 7 #+ so it is necessary to go to new line explicitly. 8 9 read -n 1 -s -p $'Control-J leaves cursor on next line. \x0a' 10 # '0a' is the hex equivalent of Control-J, linefeed. 11 echo >&2 12 13 ### 14 15 read -n 1 -s -p $'And Control-K\x0bgoes straight down.' 16 echo >&2 # Control-K is vertical tab. 17 18 # A better example of the effect of a vertical tab is: 19 20 var=$'\x0aThis is the bottom line\x0bThis is the top line\x0a' 21 echo "$var" 22 # This works the same way as the above example. However: 23 echo "$var" | col 24 # This causes the right end of the line to be higher than the left end. 25 # It also explains why we started and ended with a line feed -- 26 #+ to avoid a garbled screen. 27 28 # As Lee Maschmeyer explains: 29 # -------------------------- 30 # In the [first vertical tab example] . . . the vertical tab 31 #+ makes the printing go straight down without a carriage return. 32 # This is true only on devices, such as the Linux console, 33 #+ that can't go "backward." 34 # The real purpose of VT is to go straight UP, not down. 35 # It can be used to print superscripts on a printer. 36 # The col utility can be used to emulate the proper behavior of VT. 37 38 exit 0</PRE></TD></TR></TABLE> </P></LI><LI><P><TTCLASS="USERINPUT"><B>Ctl-Q</B></TT></P><P>Resume (XON).</P><P>This resumes <TTCLASS="FILENAME">stdin</TT> in a terminal.</P></LI><LI><P><TTCLASS="USERINPUT"><B>Ctl-S</B></TT></P><P>Suspend (XOFF).</P><P>This freezes <TTCLASS="FILENAME">stdin</TT> in a terminal. (Use Ctl-Q to restore input.)</P></LI><LI><P><TTCLASS="USERINPUT"><B>Ctl-U</B></TT></P><P>Erase a line of input, from the cursor backward to beginning of line. In some settings, <TTCLASS="USERINPUT"><B>Ctl-U</B></TT> erases the entire line of input, <ICLASS="EMPHASIS">regardless of cursor position</I>.</P></LI><LI><P><TTCLASS="USERINPUT"><B>Ctl-V</B></TT></P><P>When inputting text, <TTCLASS="USERINPUT"><B>Ctl-V</B></TT> permits inserting control characters. For example, the following two are equivalent: <TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="PROGRAMLISTING"> 1 echo -e '\x0a' 2 echo <Ctl-V><Ctl-J></PRE></TD></TR></TABLE></P><P><TTCLASS="USERINPUT"><B>Ctl-V</B></TT> is primarily useful from within a text editor.</P></LI><LI><P><TTCLASS="USERINPUT"><B>Ctl-W</B></TT></P><P>When typing text on the console or in an xterm window, <TTCLASS="USERINPUT"><B>Ctl-W</B></TT> erases from the character under the cursor backwards to the first instance of whitespace. In some settings, <TTCLASS="USERINPUT"><B>Ctl-W</B></TT> erases backwards to first non-alphanumeric character.</P></LI><LI><P><TTCLASS="USERINPUT"><B>Ctl-Z</B></TT></P><P>Pause a foreground job.</P></LI></UL></DD><DT>Whitespace</DT><DD><P><ANAME="WHITESPACEREF"></A></P><DIVCLASS="FORMALPARA"><P><B>functions as a separator, separating commands or variables. </B>Whitespace consists of either <ICLASS="FIRSTTERM">spaces</I>, <ICLASS="FIRSTTERM">tabs</I>, <ICLASS="FIRSTTERM">blank lines</I>, or any combination thereof. <ANAME="AEN1676"HREF="#FTN.AEN1676">[3]</A> In some contexts, such as <AHREF="gotchas.html#WSBAD">variable assignment</A>, whitespace
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -