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

📄 464-467.html

📁 linux-unix130.linux.and.unix.ebooks130 linux and unix ebookslinuxLearning Linux - Collection of 12 E
💻 HTML
字号:
<HTML>

<HEAD>

<TITLE>Linux Configuration and Installation:Programming in Linux</TITLE>

<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
<SCRIPT>
<!--
function displayWindow(url, width, height) {
        var Win = window.open(url,"displayWindow",'width=' + width +
',height=' + height + ',resizable=1,scrollbars=yes');
}
//-->
</SCRIPT>
</HEAD>

 -->




<!--ISBN=1558285660//-->

<!--TITLE=Linux Configuration and Installation//-->

<!--AUTHOR=Patrick Volkerding//-->

<!--AUTHOR=Kevin Reichard//-->

<!--AUTHOR=Eric Foster//-->

<!--PUBLISHER=IDG Books Worldwide, Inc.//-->

<!--IMPRINT=M & T Books//-->

<!--CHAPTER=10//-->

<!--PAGES=464-467//-->

<!--UNASSIGNED1//-->

<!--UNASSIGNED2//-->



<CENTER>

<TABLE BORDER>

<TR>

<TD><A HREF="460-464.html">Previous</A></TD>

<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>

<TD><A HREF="467-470.html">Next</A></TD>

</TR>

</TABLE>

</CENTER>

<P><BR></P>

<H3><A NAME="Heading19"></A><FONT COLOR="#000077">Linux Scripting Languages</FONT></H3>

<P>In addition to the programming languages discussed earlier, Linux offers even more, including a number of scripting languages. A scripting language is a lot like the language that comes with the UNIX shell. The main difference between a programming language and a scripting language is that <I>scripting languages</I> are usually interpreted instead of compiled, and scripting languages usually make it easier to launch Linux commands from within your programs&#151;called <I>scripts</I> when you use a scripting language. As you can tell, the line between programming languages and scripting languages is blurry.</P>

<P>Of the scripting languages available on Linux, the two hottest languages are Tcl and Perl, while <B>gawk</B> continues to attract a lot of attention.</P>

<H4 ALIGN="LEFT"><A NAME="Heading20"></A><FONT COLOR="#000077">Tcl</FONT></H4>

<P>Tcl, short for the Tool Command Language, is a very handy scripting language that runs on most UNIX platforms and Windows NT. Combined with Tcl&#146;s X Window toolkit, called Tk, you can build a lot of neat X Window graphical programs without a lot of coding.

</P>

<P>In addition, Tcl is made to be embedded in C programs, so you can use Tcl as a standard extension language for your spreadsheet, game, or other software you write.</P>

<P>We mostly use Tcl to create programs that have a friendly user interface, that look like Motif programs, and that can run on a wide number of systems. Tcl and the Tk toolkit present something akin to the Motif look and feel&#151;not close enough for purists, but close enough for most users. This is a great benefit because the Motif libraries don&#146;t ship with Linux, but Tcl does.</P>

<P>Tcl is a scripting language, much like the languages built into <B>sh</B> and <B>ksh</B>, the most common UNIX command shells. The language has some nice features for handling strings and lists (of strings&#151;just about <I>everything</I> is a string in a Tcl program).</P>

<P>The Tk toolkit then acts as an add-on to Tcl, allowing you to easily build widgets and create an X Window user interface. The whole concept of widgets, though, is likely to be daunting unless you&#146;ve programmed with one of the many X toolkits, such as Motif. Each widget acts as a part of your user interface, for example, a list of files, a push button to exit the program, and so on. If you have worked with Motif or the Athena widgets, you&#146;ll catch on to the concepts of Tk pretty fast. Even if you haven&#146;t worked with the Motif or Athena libraries, we found the basics of Tcl very easy to grasp. (There are some frustrating parts to Tcl, though.)</P>

<P>The Tk add-on to Tcl provides most of the standard set of widgets you&#146;d expect. These widgets mirror most of the main widgets in the Motif toolkit, except for the handy option-menu, combo-box, and notebook widgets. Tcl exceeds Motif in a number of areas, too, especially with the canvas widget, which allows you to place graphic &#147;objects&#148; such as lines, rectangles, B&#233;zi&#233;r curves, and even other widgets inside the canvas.</P>

<P><FONT SIZE="+1"><B>Scripting with Tcl</B></FONT></P>

<P>Like most scripting languages, Tcl uses a dollar sign, $, to get the value of a variable. Everything in Tcl is a text string, so it needs a special character to differentiate a string from the value held within a variable. Thus:

</P>

<!-- CODE SNIP //-->

<PRE>

     variable

</PRE>

<!-- END CODE SNIP //-->

<P>is just the literal string <I>variable</I>, while</P>

<!-- CODE SNIP //-->

<PRE>

     $variable

</PRE>

<!-- END CODE SNIP //-->

<P>returns the value stored in the variable named, appropriately enough, <I>variable</I>. This is the same as most shell scripting languages. (There are some tricky aspects to this, though. We found that simple typos&#151;such as forgetting the $&#151;were responsible for most of our Tcl errors.)</P>

<P>For example, if you have a directory name in the variable <I>dir</I> and you want to use the <B>cd</B> command to change to that directory, you issue the following Tcl command:</P>

<!-- CODE SNIP //-->

<PRE>

     cd $dir

</PRE>

<!-- END CODE SNIP //-->

<P>The basic syntax for Tcl seems like a cross between Lisp and C. The basic function, called proc, looks much like a C function, for example:

</P>

<!-- CODE SNIP //-->

<PRE>

     proc add_one &#123; value &#125; &#123;



         return [expr $value&#43;1]

     &#125;

</PRE>

<!-- END CODE SNIP //-->

<P>The braces give it a definite C feeling. The Lispishness comes from the use of the <B>set</B> command, instead of assignment. That is, instead of a C statement like:</P>

<!-- CODE SNIP //-->

<PRE>

     a = b;

</PRE>

<!-- END CODE SNIP //-->

<P>in Tcl you code this as:

</P>

<!-- CODE SNIP //-->

<PRE>

     set a $b

</PRE>

<!-- END CODE SNIP //-->

<P>(Remembering all the while that the $ can trip you up at first.)

</P>

<P>One nice thing about Tcl is its ability to use variables at any time, without predeclaring them&#151;except for arrays, which you need to indicate are arrays before using them with widget commands.</P><P><BR></P>

<CENTER>

<TABLE BORDER>

<TR>

<TD><A HREF="460-464.html">Previous</A></TD>

<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>

<TD><A HREF="467-470.html">Next</A></TD>

</TR>

</TABLE>

</CENTER>





</td>
</tr>
</table>

<!-- begin footer information -->





</body></html>

⌨️ 快捷键说明

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