linux shell scripts 学习

说明:代码前面的编号是使用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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值