Shell scripting 1 - introduction

来源:互联网 发布:linux多进程服务器 编辑:程序博客网 时间:2024/05/18 14:44

Purpose Of This Tutorial

This tutorial is written to help people understand some of the basics of shellscript programming, and hopefully to introduce some of the possibilities of simple butpowerful programming available under the bourne shell. As such, it has been written asa basis for one-on-one or group tutorials and exercises, and as a reference for subsequentuse.

A Brief History of sh

Steve Bourne, wrote the Bourne shell which appeared in the Seventh Edition Bell Labs Research version of Unix.
Many other shells have been written; this particular tutorial concentrateson the Bourne and the Bourne Again shells.
Other shells include the Korn Shell (ksh), the C Shell (csh), and variations such as tcsh.
This tutorial does not cover those shells. Maybe a future version will cover ksh; I donot intend to write a tutorial for csh, ascsh programming is considered harmful.

Typographical Conventions Used in This Tutorial

Significant words will be written in italics when mentioned for thefirst time.

Code segments and script output will be displayed as preformatted text.
Command-line entries will be preceded by the Dollar sign ($). If your prompt is different,enter the command:

PS1="$ " ; export PS1

Then your interactions shouldmatch the examples given (such as $ ./my-script.sh below).
Script output (such as "Hello World" below) is displayed at the start of the line.

$ echo '#!/bin/sh' > my-script.sh$ echo 'echo Hello World' >> my-script.sh$ chmod 755 my-script.sh$ ./my-script.shHello World$
Entire scripts will be surrounded by thick horizontal rules and include a referencewhere available to the plain text of the script:
first.sh
#!/bin/sh# This is a comment!echo Hello World        # This is a comment, too!

Note that to make a file executable, you must set the eXecutable bit, and for a shellscript, the Readable bit must also be set:
$ chmod a+rx first.sh

原创粉丝点击