码迷,mamicode.com
首页 > 系统相关 > 详细

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

时间:2016-01-01 14:48:37      阅读:193      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!