⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 shells.html

📁 FreeBSD安装说明概述 FreeBSD 提供了一个以文字为主
💻 HTML
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta name="generator" content="HTML Tidy, see www.w3.org" /><title>Shells</title><meta name="GENERATOR" content="Modular DocBook HTML Stylesheet Version 1.7" /><link rel="HOME" title="FreeBSD 使用手册" href="index.html" /><link rel="UP" title="UNIX Basics" href="basics.html" /><link rel="PREVIOUS" title="Daemons, Signals, and Killing Processes"href="basics-daemons.html" /><link rel="NEXT" title="Text Editors" href="editors.html" /><link rel="STYLESHEET" type="text/css" href="docbook.css" /><meta http-equiv="Content-Type" content="text/html; charset=GB2312" /></head><body class="SECT1" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#840084"alink="#0000FF"><div class="NAVHEADER"><table summary="Header navigation table" width="100%" border="0" cellpadding="0"cellspacing="0"><tr><th colspan="3" align="center">FreeBSD 使用手册</th></tr><tr><td width="10%" align="left" valign="bottom"><a href="basics-daemons.html"accesskey="P">Prev</a></td><td width="80%" align="center" valign="bottom">Chapter 3. UNIX Basics</td><td width="10%" align="right" valign="bottom"><a href="editors.html"accesskey="N">Next</a></td></tr></table><hr align="LEFT" width="100%" /></div><div class="SECT1"><h1 class="SECT1"><a id="SHELLS" name="SHELLS">3.9. Shells</a></h1><p>In FreeBSD, a lot of everyday work is done in a command line interface called a shell.A shell's main job is to take commands from the input channel and execute them. A lot ofshells also have built in functions to help everyday tasks such as file management, fileglobbing, command line editing, command macros, and environment variables. FreeBSD comeswith a set of shells, such as <tt class="COMMAND">sh</tt>, the Bourne Shell, and <ttclass="COMMAND">tcsh</tt>, the improved C-shell. Many other shells are available from theFreeBSD Ports Collection, such as <tt class="COMMAND">zsh</tt> and <ttclass="COMMAND">bash</tt>.</p><p>Which shell do you use? It is really a matter of taste. If you are a C programmer youmight feel more comfortable with a C-like shell such as <tt class="COMMAND">tcsh</tt>. Ifyou have come from Linux or are new to a <span class="TRADEMARK">UNIX</span>&reg; commandline interface you might try <tt class="COMMAND">bash</tt>. The point is that each shellhas unique properties that may or may not work with your preferred working environment,and that you have a choice of what shell to use.</p><p>One common feature in a shell is filename completion. Given the typing of the firstfew letters of a command or filename, you can usually have the shell automaticallycomplete the rest of the command or filename by hitting the <b class="KEYCAP">Tab</b> keyon the keyboard. Here is an example. Suppose you have two files called <ttclass="FILENAME">foobar</tt> and <tt class="FILENAME">foo.bar</tt>. You want to delete<tt class="FILENAME">foo.bar</tt>. So what you would type on the keyboard is: <ttclass="COMMAND">rm fo[<b class="KEYCAP">Tab</b>].[<b class="KEYCAP">Tab</b>]</tt>.</p><p>The shell would print out <tt class="COMMAND">rm foo[BEEP].bar</tt>.</p><p>The [BEEP] is the console bell, which is the shell telling me it was unable to totallycomplete the filename because there is more than one match. Both <ttclass="FILENAME">foobar</tt> and <tt class="FILENAME">foo.bar</tt> start with <varclass="LITERAL">fo</var>, but it was able to complete to <var class="LITERAL">foo</var>.If you type in <var class="LITERAL">.</var>, then hit <b class="KEYCAP">Tab</b> again,the shell would be able to fill in the rest of the filename for you.</p><p>Another feature of the shell is the use of environment variables. Environmentvariables are a variable key pair stored in the shell's environment space. This space canbe read by any program invoked by the shell, and thus contains a lot of programconfiguration. Here is a list of common environment variables and what they mean:</p><div class="INFORMALTABLE"><a id="AEN4761" name="AEN4761"></a><table border="0" frame="void" class="CALSTABLE"><col /><col /><thead><tr><th>Variable</th><th>Description</th></tr></thead><tbody><tr><td><tt class="ENVAR">USER</tt></td><td>Current logged in user's name.</td></tr><tr><td><tt class="ENVAR">PATH</tt></td><td>Colon separated list of directories to search for binaries.</td></tr><tr><td><tt class="ENVAR">DISPLAY</tt></td><td>Network name of the X11 display to connect to, if available.</td></tr><tr><td><tt class="ENVAR">SHELL</tt></td><td>The current shell.</td></tr><tr><td><tt class="ENVAR">TERM</tt></td><td>The name of the user's terminal. Used to determine the capabilities of theterminal.</td></tr><tr><td><tt class="ENVAR">TERMCAP</tt></td><td>Database entry of the terminal escape codes to perform various terminalfunctions.</td></tr><tr><td><tt class="ENVAR">OSTYPE</tt></td><td>Type of operating system. e.g., FreeBSD.</td></tr><tr><td><tt class="ENVAR">MACHTYPE</tt></td><td>The CPU architecture that the system is running on.</td></tr><tr><td><tt class="ENVAR">EDITOR</tt></td><td>The user's preferred text editor.</td></tr><tr><td><tt class="ENVAR">PAGER</tt></td><td>The user's preferred text pager.</td></tr><tr><td><tt class="ENVAR">MANPATH</tt></td><td>Colon separated list of directories to search for manual pages.</td></tr></tbody></table></div><p>Setting an environment variable differs somewhat from shell to shell. For example, inthe C-Style shells such as <tt class="COMMAND">tcsh</tt> and <ttclass="COMMAND">csh</tt>, you would use <tt class="COMMAND">setenv</tt> to setenvironment variables. Under Bourne shells such as <tt class="COMMAND">sh</tt> and <ttclass="COMMAND">bash</tt>, you would use <tt class="COMMAND">export</tt> to set yourcurrent environment variables. For example, to set or modify the <ttclass="ENVAR">EDITOR</tt> environment variable, under <tt class="COMMAND">csh</tt> or <ttclass="COMMAND">tcsh</tt> a command like this would set <tt class="ENVAR">EDITOR</tt> to<tt class="FILENAME">/usr/local/bin/emacs</tt>:</p><pre class="SCREEN"><samp class="PROMPT">%</samp> <kbdclass="USERINPUT">setenv EDITOR /usr/local/bin/emacs</kbd></pre><p>Under Bourne shells:</p><pre class="SCREEN"><samp class="PROMPT">%</samp> <kbdclass="USERINPUT">export EDITOR="/usr/local/bin/emacs"</kbd></pre><p>You can also make most shells expand the environment variable by placing a <varclass="LITERAL">$</var> character in front of it on the command line. For example, <ttclass="COMMAND">echo $TERM</tt> would print out whatever <tt class="ENVAR">$TERM</tt> isset to, because the shell expands <tt class="ENVAR">$TERM</tt> and passes it on to <ttclass="COMMAND">echo</tt>.</p><p>Shells treat a lot of special characters, called meta-characters as specialrepresentations of data. The most common one is the <var class="LITERAL">*</var>character, which represents any number of characters in a filename. These specialmeta-characters can be used to do filename globbing. For example, typing in <ttclass="COMMAND">echo *</tt> is almost the same as typing in <tt class="COMMAND">ls</tt>because the shell takes all the files that match <var class="LITERAL">*</var> and putsthem on the command line for <tt class="COMMAND">echo</tt> to see.</p><p>To prevent the shell from interpreting these special characters, they can be escapedfrom the shell by putting a backslash (<var class="LITERAL">\</var>) character in frontof them. <tt class="COMMAND">echo $TERM</tt> prints whatever your terminal is set to. <ttclass="COMMAND">echo \$TERM</tt> prints <tt class="ENVAR">$TERM</tt> as is.</p><div class="SECT2"><h2 class="SECT2"><a id="CHANGING-SHELLS" name="CHANGING-SHELLS">3.9.1. Changing YourShell</a></h2><p>The easiest way to change your shell is to use the <tt class="COMMAND">chsh</tt>command. Running <tt class="COMMAND">chsh</tt> will place you into the editor that is inyour <tt class="ENVAR">EDITOR</tt> environment variable; if it is not set, you will beplaced in <tt class="COMMAND">vi</tt>. Change the ``Shell:'' line accordingly.</p><p>You can also give <tt class="COMMAND">chsh</tt> the <var class="OPTION">-s</var>option; this will set your shell for you, without requiring you to enter an editor. Forexample, if you wanted to change your shell to <tt class="COMMAND">bash</tt>, thefollowing should do the trick:</p><pre class="SCREEN"><samp class="PROMPT">%</samp> <kbd class="USERINPUT">chsh -s /usr/local/bin/bash</kbd></pre><p>Running <tt class="COMMAND">chsh</tt> with no parameters and editing the shell fromthere would work also.</p><div class="NOTE"><blockquote class="NOTE"><p><b>Note:</b> The shell that you wish to use <span class="emphasis"><iclass="EMPHASIS">must</i></span> be present in the <tt class="FILENAME">/etc/shells</tt>file. If you have installed a shell from the <a href="ports.html">ports collection</a>,then this should have been done for you already. If you installed the shell by hand, youmust do this.</p><p>For example, if you installed <tt class="COMMAND">bash</tt> by hand and placed it into<tt class="FILENAME">/usr/local/bin</tt>, you would want to:</p><pre class="SCREEN"><samp class="PROMPT">#</samp> <kbdclass="USERINPUT">echo &quot;/usr/local/bin/bash&quot; &gt;&gt; /etc/shells</kbd></pre><p>Then rerun <tt class="COMMAND">chsh</tt>.</p></blockquote></div></div></div><div class="NAVFOOTER"><hr align="LEFT" width="100%" /><table summary="Footer navigation table" width="100%" border="0" cellpadding="0"cellspacing="0"><tr><td width="33%" align="left" valign="top"><a href="basics-daemons.html"accesskey="P">Prev</a></td><td width="34%" align="center" valign="top"><a href="index.html"accesskey="H">Home</a></td><td width="33%" align="right" valign="top"><a href="editors.html"accesskey="N">Next</a></td></tr><tr><td width="33%" align="left" valign="top">Daemons, Signals, and Killing Processes</td><td width="34%" align="center" valign="top"><a href="basics.html"accesskey="U">Up</a></td><td width="33%" align="right" valign="top">Text Editors</td></tr></table></div></body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -