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

📄 unx11.htm

📁 Linux Unix揭密.高质量电子书籍.对学习Linux有大帮助,欢迎下载学习.
💻 HTM
📖 第 1 页 / 共 5 页
字号:
<HTML>

<HEAD>

<TITLE>UNIX Unleashed unx11.htm</TITLE>

<LINK REL="ToC" HREF="index.htm">

<LINK REL="Next" HREF="unx12.htm">

<LINK REL="Previous" HREF="unx10.htm"></HEAD>

<BODY TEXT="#000000" LINK="#0000FF" VLINK="#800080" bgcolor=white>

<P><A HREF="unx10.htm"><IMG SRC="bluprev.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="Previous Page"></A>

<A HREF="index.htm"><IMG SRC="blutoc.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="TOC"></A>

<A HREF="unx12.htm"><IMG SRC="blunext.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="Next Page"></A>

<A HREF="index.htm"><IMG SRC="bluprev.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="Home"></A>

</P><UL>

<LI>

<A HREF="#I1">11</A></LI>

<UL>

<LI>

<A HREF="#I3">Bourne Shell</A></LI>

<UL>

<UL>

<UL>

<LI>

<A HREF="#I4">By Richard E. Rummel</A></LI></UL></UL>

<LI>

<A HREF="#I5">Shell Basics</A></LI>

<UL>

<LI>

<A HREF="#I6">How the Shell Interprets Commands</A></LI>

<LI>

<A HREF="#I7">Entering Simple Commands</A></LI>

<UL>

<LI>

<A HREF="#I8">Redirection of Input and Output</A></LI>

<LI>

<A HREF="#I9">Entering Multiple Commands on One Line</A></LI>

<LI>

<A HREF="#I10">Entering Commands Too Long for One Line</A></LI>

<LI>

<A HREF="#I11">Filename Substitutions on the Command Line</A></LI>

<LI>

<A HREF="#I12">Substitution of Variable Data</A></LI>

<LI>

<A HREF="#I13">Substituting the Results of Commands in a Command Line</A></LI>

<LI>

<A HREF="#I14">Escaping from the Special Characters</A></LI></UL>

<LI>

<A HREF="#I15">Entering Data from the Shell</A></LI></UL>

<LI>

<A HREF="#I16">Shell Options</A></LI>

<UL>

<LI>

<A HREF="#I17">The Restricted Shell</A></LI>

<UL>

<LI>

<A HREF="#I18">Changing Shell Options with set</A></LI></UL></UL>

<LI>

<A HREF="#I19">Variables</A></LI>

<UL>

<LI>

<A HREF="#I20">Defining Your Own (User-Defined) Variables</A></LI>

<LI>

<A HREF="#I21">Conditional Variable Substitution</A></LI>

<UL>

<LI>

<A HREF="#I22">Substituting Default Values for Variables</A></LI>

<LI>

<A HREF="#I23">Conditional Variable Substitution with Error Checking</A></LI></UL>

<LI>

<A HREF="#I24">Positional Variables or Parameters</A></LI>

<UL>

<LI>

<A HREF="#I25">Special Variables in the Bourne Shell</A></LI>

<LI>

<A HREF="#I26">Environment Variables</A></LI>

<LI>

<A HREF="#I27">Preventing Variables from Being Changed</A></LI>

<LI>

<A HREF="#I28">Making Variables Available to Subshells with export</A></LI></UL></UL>

<LI>

<A HREF="#I29">Shell Programming</A></LI>

<UL>

<LI>

<A HREF="#I30">What Is a Program?</A></LI>

<LI>

<A HREF="#I31">A Simple Program</A></LI>

<LI>

<A HREF="#I32">The Shell as a Language</A></LI>

<LI>

<A HREF="#I33">Using Data Variables in Shell Programs</A></LI>

<LI>

<A HREF="#I34">Entering Comments in Shell Programs</A></LI>

<LI>

<A HREF="#I35">Doing Arithmetic on Shell Variables</A></LI>

<LI>

<A HREF="#I36">Passing Arguments to Shell Programs</A></LI>

<LI>

<A HREF="#I37">Decision Making in Shell Programs</A></LI>

<UL>

<LI>

<A HREF="#I38">The if-then Statement</A></LI>

<LI>

<A HREF="#I39">Data Output from Shell Programs</A></LI>

<LI>

<A HREF="#I40">The if-then-else Statement</A></LI>

<LI>

<A HREF="#I41">Testing Conditions with test</A></LI>

<LI>

<A HREF="#I42">Testing Character Data</A></LI>

<LI>

<A HREF="#I43">Testing Numeric Data</A></LI>

<LI>

<A HREF="#I44">Testing for Files</A></LI>

<LI>

<A HREF="#I45">Combining and Negating test Conditions</A></LI>

<LI>

<A HREF="#I46">A Shorthand Method of Doing Tests</A></LI>

<LI>

<A HREF="#I47">The Null Command</A></LI>

<LI>

<A HREF="#I48">Displaying the Program Name</A></LI>

<LI>

<A HREF="#I49">Nested if Statements and the elif Construct</A></LI>

<LI>

<A HREF="#I50">Reading Data into a Program Interactively</A></LI>

<LI>

<A HREF="#I51">The case Statement</A></LI></UL>

<LI>

<A HREF="#I52">Building Repetitions into a Program</A></LI>

<UL>

<LI>

<A HREF="#I53">Repeating Within a while Loop</A></LI>

<LI>

<A HREF="#I54">Repeating Within an until Loop</A></LI>

<LI>

<A HREF="#I55">Processing an Arbitrary Number of Parameters with shift</A></LI>

<LI>

<A HREF="#I56">Repeating Within a for Loop</A></LI>

<LI>

<A HREF="#I57">Getting Out of a Loop from the Middle</A></LI>

<LI>

<A HREF="#I58">Structured Shell Programming Using Functions</A></LI>

<LI>

<A HREF="#I59">Handling the Unexpected with trap</A></LI></UL>

<LI>

<A HREF="#I60">Conditional Command Execution with the And/Or Constructs</A></LI>

<UL>

<LI>

<A HREF="#I61">Reading UNIX-Style Options</A></LI></UL></UL>

<LI>

<A HREF="#I62">Customizing the Shell</A></LI>

<UL>

<LI>

<A HREF="#I63">Customizing the Shell with Environment Variables</A></LI>

<UL>

<LI>

<A HREF="#I64">Changing Your Command-Line Prompt with PS</A></LI>

<LI>

<A HREF="#I65">Adding Command-Line Separators with IFS</A></LI>

<LI>

<A HREF="#I66">Checking Multiple Mailboxes with MAILPATH</A></LI>

<LI>

<A HREF="#I67">Automating Environment Changes</A></LI></UL>

<LI>

<A HREF="#I68">Adding Your Own Commands and Functions</A></LI></UL>

<LI>

<A HREF="#I69">Specialized Topics</A></LI>

<UL>

<LI>

<A HREF="#I70">Debugging Shell Programs</A></LI>

<LI>

<A HREF="#I71">Grouping Commands</A></LI>

<LI>

<A HREF="#I72">Using the Shell Layer Manager shl</A></LI></UL>

<LI>

<A HREF="#I73">Summary</A></LI></UL></UL></UL>



<H1 ALIGN="CENTER">

<CENTER><A ID="I1" NAME="I1">

<BR>

<FONT SIZE=5><A ID="I2" NAME="I2"></A><B>11</B>

<BR></FONT></A></CENTER></H1>

<H2 ALIGN="CENTER">

<CENTER><A ID="I3" NAME="I3">

<FONT SIZE=5><B>Bourne Shell</B>

<BR></FONT></A></CENTER></H2>

<H5 ALIGN="CENTER">

<CENTER><A ID="I4" NAME="I4">

<FONT SIZE=3><B>By Richard E. Rummel</B>

<BR></FONT></A></CENTER></H5>

<P>In this chapter, you learn how to get the most out of the Bourne shell, one of the most used of the UNIX shells. You also learn how to store data in your own variables, how to customize your environment with environment variables, and how to group 
commands together to form shell programs.

<BR></P>

<H3 ALIGN="CENTER">

<CENTER><A ID="I5" NAME="I5">

<FONT SIZE=4><B>Shell Basics</B>

<BR></FONT></A></CENTER></H3>

<P>The Bourne shell was written by Stephen Bourne at Bell Laboratories, where UNIX was originally developed. Because it is found on most UNIX systems, many software developers work under the assumption that the Bourne shell is available on a UNIX system. 
This use does not mean that it is the best shell, but simply that it is the most common. Other shells, most notably the Korn shell, were written to enhance the Bourne shell, so shell programs written for Bourne run under the Korn shell. In some literature, 

the Bourne shell is called the UNIX system Version 7 shell.

<BR></P>

<H4 ALIGN="CENTER">

<CENTER><A ID="I6" NAME="I6">

<FONT SIZE=3><B>How the Shell Interprets Commands</B>

<BR></FONT></A></CENTER></H4>

<P>The first exposure most people have to the Bourne shell is as an interactive shell. After logging on the system and seeing any messages from the system administrator, the user sees a shell prompt. For users other than the super-user, the default prompt 

for the interactive Bourne shell is a dollar sign ($). When you see the dollar sign ($), the interactive shell is ready to accept a line of input, which it interprets. When the super-user logs in, he or she sees the pound sign (#) as a prompt. It is a 
reminder that as super-user some of the built-in protections are not available and that extra care is necessary in this mode.

<BR></P>

<HR ALIGN=CENTER>

<NOTE>

<IMG SRC="note.gif" WIDTH = 35 HEIGHT = 35><B>NOTE:</B> On UNIX systems the super-user, also referred to as root, is without restriction. The super-user can write to any directory and can remove any file. File permissions do not apply to the super-user. 
The password for the super-user is usually closely held by the system administrator.

<BR></NOTE>

<HR ALIGN=CENTER>

<P>The shell sees a line of input as a string of characters terminated with a newline character, which is usually the result of pressing Enter on your keyboard. The length of the input line has nothing to do with the width of your computer display. When 
the shell sees the newline character, it begins to interpret the line.

<BR></P>

<H4 ALIGN="CENTER">

<CENTER><A ID="I7" NAME="I7">

<FONT SIZE=3><B>Entering Simple Commands</B>

<BR></FONT></A></CENTER></H4>

<P>The most common form of input to the shell is the simple command, in which a command name is followed by any number of arguments. In the example

<BR></P>

<PRE>$ <B>ls </B>file1 file2 file3</PRE>

<P>ls is the command and <I>file1</I>, <I>file2</I>, and <I>file3</I> are the arguments. The command is any UNIX executable. It is the responsibility of the command, not the shell, to interpret the arguments. Many UNIX commands, but certainly not all, take 

the following form:

<BR></P>

⌨️ 快捷键说明

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