初识脚本
Posted jsjobs
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了初识脚本相关的知识,希望对你有一定的参考价值。
1.1 脚本认识
- 1 #!/bin/bash
第一行,通常用来指定执行脚本的shell ,/bin/bash是CentOS 默认的shell 如果写到第二行,就是注释了
- 1 #!/bin/sh
这样写也是可以的,sh是bash的软链接,和#!/bin/bash 是没有区别的,理规范的开头使用#!/bin/bash
1.2 查看bash版本
-
1 [[email protected] scripts]# bash --version 2 GNU bash, version 4.1.2(2)-release (x86_64-redhat-linux-gnu) 3 Copyright (C) 2009 Free Software Foundation, Inc. 4 License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> 5 6 This is free software; you are free to change and redistribute it. 7 There is NO WARRANTY, to the extent permitted by law. 8 [[email protected] scripts]# cat test_1.sh 9 #!/bin/bash 10 user=`whoami` 11 echo $user 12 [[email protected] scripts]# sh test_1.sh 13 root 14 [[email protected] scripts]# ./test_1.sh 15 root 16 [[email protected] scripts]# . test_1.sh 17 root 18 [[email protected] scripts]# source test_1.sh 19 root 20 [[email protected] scripts]# /bin/bash test_1.sh 21 root 22 [[email protected] scripts]# /bin/sh test_1.sh 23 root 24 [[email protected] scripts]# /server/scripts/test_1.sh 25 root
1.3 书写脚本
1.3.1 执行脚本
1.3.1.1 小结:
执行脚本的方法有:sh ./ . source /bin/bash /bin/sh pwd/
1.4 继承脚本变量
-
1 [[email protected] scripts]# sh test_1.sh 2 root 3 [[email protected] scripts]# echo $user 4 5 [[email protected] scripts]# ./test_1.sh 6 root 7 [[email protected] scripts]# echo $user 8 9 [[email protected] scripts]# bash test_1.sh 10 root 11 [[email protected] scripts]# echo $user 12 13 [[email protected] scripts]# . test_1.sh 14 root 15 [[email protected] scripts]# echo $user 16 root 17 [[email protected] scripts]# source test_1.sh 18 root 19 [[email protected] scripts]# echo $user 20 root
1.4.1.1 小结
继承:source 和 . 能继承脚本的变量,其它命令皆不能继承
以上是关于初识脚本的主要内容,如果未能解决你的问题,请参考以下文章
初识OpenGL 片段着色器(Fragment Shader)