shell简单入门脚本

一、编写两个简单的shell脚本 (shell脚本需要以.sh扩展名)

[root@shellhost ~]# cd /scripts/day1/
[root@shellhost day1]# vim test1.sh

vim test2.sh

 

 二、执行脚本 

方法一:

bash test1.sh 
或者
sh test1.sh 

方法二:

给脚本添加执行权限:chmod +x test1.sh再如下执行脚本

./test1.sh

方法三:

source test1.sh
或者
. test1.sh 

方法四:

sh < test1.sh 
或者
cat test1.sh | sh

 

#区别

 三、快速生成脚本开头的版本版权注释信息

[root@localhost day1]# vim ~/.vimrc
autocmd BufNewFile *.py,*.cc,*.sh,*.java exec ":call SetTitle()"

func SetTitle()
    if expand("%:e") == 'sh'
        call setline(1,"#!/bin/bash")
        call setline(2,"##############################################################")
        call setline(3, "# File Name: ".expand("%"))
        call setline(4, "# Version: V1.0")
        call setline(5, "# Author: xiaohong")
        call setline(6, "# Email: xiaohong@163.com")
        call setline(7, "# Organization: http://www.cnblogs.com/xiaohong/")
        call setline(8, "# Created Time : ".strftime("%F %T"))
        call setline(9, "# Description:")
        call setline(10,"##############################################################")
        call setline(11, "")
    endif
endfunc

 此时创建一个以 .sh结尾的文件自动会生成版本注释信息

[root@localhost day1]# vim test.sh

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值