0
点赞
收藏
分享

微信扫一扫

shell简单入门脚本

小安子啊 2022-02-24 阅读 62

一、编写两个简单的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

 

 

举报

相关推荐

0 条评论