首页 > 系统服务 > 详细

Shell编程进阶 1.2 shell结构及执行

时间:2016-01-01 14:45:55      阅读:133      评论:0      收藏:0      [点我收藏+]

创建一个shell脚本

mkdir shell
vim first.sh
#!/bin/bash
##The first test shell script.
##Written by wangshaojun.

ls /tmp/
echo "my home is $HOME"
echo "This is first script"

执行shell脚本,两种方法

bash first.sh

mysql.sock www_slow.log
2015-12-31.wangshaojun.root.history-timestamp pear www.sock
2016-01-01.wangshaojun.root.history-timestamp www1.sock
my home is /root
This is first script.

或者 

sh first.sh

第二种方法

chmod a+x first.sh
./first.sh

绝对路径

/root/shell/first.sh

 

脚本的执行过程

sh -x first.sh

+ ls /tmp
12334 mysql.sock www_slow.log
2015-12-31.wangshaojun.root.history-timestamp pear www.sock
2016-01-01.wangshaojun.root.history-timestamp www1.sock
+ echo ‘my home is /root‘
my home is /root
+ echo ‘This is first script.‘
This is first script.

 

可以排查错误

 

Shell编程进阶 1.2 shell结构及执行

原文:http://www.cnblogs.com/wangshaojun/p/5093200.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!