Shell编程实例

参考文档:https://www.cnblogs.com/xuziyu/p/10687781.html

实例1:输出字符串

脚本test01.sh

#!/bin/bash
#打印输出
echo "#######################################"
echo "This is the first shell script!"
echo "#######################################"  

 

执行命令:

sh test01.sh

 

执行结果:

#######################################
This is the first shell script!
#######################################

  

实例2:变量引用

1)变量定义等号前后不能有空格;

2)使用单引号、双引号、无引号定义的变量,是静态变量;

3)使用反引号引用的变量为命令,是动态变量;

4)引用变量用${},变量放在大括号里面;

脚本:test02.sh

#!/bin/bash
#变量引用
echo "######################################################################"
name=wzl
date=`date`
echo "my name is ${name}"
echo "now time is ${date}"
echo "######################################################################"

  

执行命令;

sh test02.sh

  

执行结果:

######################################################################
my name is wzl
now time is Mon Jun  8 20:24:51 CST 2020
######################################################################

  

 

posted @ 2020-06-08 20:26  雨后的太阳  阅读(211)  评论(0编辑  收藏  举报