说明:代码前面的编号是使用cat -n sh* 显示出来的,并非源代码中
1、sh01.sh
1 #!/bin/bash
2 #program:
3 # This program is used to show "hello world!" in screen.
4 #History:
5 # 2010/12/26 WDH 1st
6 PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
7 export PATH
8 echo -e "Hello world! /n"
9 exit 0
2、sh02.sh
1 #!/bin/bash
2 #Program:
3 #这个程序是让用户输入他的first name和last name,最后显示他的full name
4 # 2010年12月26日 15:50:32 user:WDH
5 # Version:1.0
6 PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
7 export PATH
8
9 read -p "请输入您的firstname:" firstname
10 read -p "请输入您的lastname:" lastname
11 echo -e "/n 您的fullname是:$firstname $lastname"
3、sh03.sh
1 #!/bin/bash
2 #Program:
3 #这个程序用来按照日期产生3个不同的文件
4 #History
5 #2010年12月26日 16:33:19 user:WDH
6 # Version:1.0
7 PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
8 export PATH
9
10 # 1、用户输入文件名称,并获取fileuser变量
11 echo -e "将按照您输入的变量产生3个文件"
12 read -p "请输入您的文件名:" fileuser
13
14 # 2、为了避免用户随意按Enter,使用变量功能分析是否设置了文件名?
15 filename=${fileuser:-"filename"}
16
17 # 3、开始使用date创建所需要的文件
18 date1=`date --date='2 days ago' +%Y%m%d`
19 date2=`date --date='1 days ago' +%Y%m%d`
20 date3=`date +%Y%m%d`
21 file1="$filename""$date1"
22 file2="$filename""$date2"
23 file3="$filename""$date3"
24
25 # 4、创建3个文件
26 touch $file1
27 touch $file2
28 touch $file3
4、sh04.sh
1 #!/bin/bash
2 #Program:
3 #这个程序用来求两个整数的乘积
4 #History
5 # 2010年12月26日 17:23:52 user:WDH
6 # Version:1.0
7 PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
8 export PATH
9
10 echo -e "此程序将用来计算您输入的2个整数的乘积 /n"
11 read -p "请输入第一个整数:" firstNO
12 read -p "请输入第二个整数:" secondNO
13 total=$(($firstNO * $secondNO))
14 echo -e "2个整数的乘积=" $total