linux 执行shell脚本

1、创建shell脚本:/home/test.sh

cd /home/

vim tesh.sh   #linux不区分后缀,.sh 只是为了方便使用者;

test.sh 文件首行定义格式: #!/bin/bash  表示该文件是用bash shell来执行;

内容随便写,例如: fdisk -l | grep 'Disk /dev/sda' | awk '{print $3}'     #显示sda分区的大小

2、执行方式:

a、相对路径(需要给执行权限):  chmod u+x test.sh

cd /home

./test.sh 

b、 绝对路径下

/home/test.sh

c、 使用bash、sh来执行,不需要给执行权限

bash test.sh

sh test.sh 

 

posted @ 2017-06-18 18:24  逍遥小薇  阅读(170)  评论(0编辑  收藏  举报