Shell scripting 1 - introduction

本教程旨在帮助读者理解shell脚本编程的基础,并介绍BourneShell下简单而强大的编程可能性。教程适合一对一或小组教学使用,并作为后续参考。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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, as csh 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.sh
Hello 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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值