#!/bin/bash是指此脚本使用/bin/bash来解释执行。
其中,#!是一个特殊的表示符,其后,跟着解释此脚本的shell路径。
bash只是shell的一种,还有很多其它shell,如:sh,csh,ksh,tcsh,...
我们可以通过以下一个示例来进行实验,了解#!/bin/bash的使用。
除第一行外,脚本中所有以“#”开头的行都是注释。
1)#!/bin/bash只能放在第一行,如果后面还有#!,那么只能看成是注释。
这里有三个脚本(脚本都要使用”chmod +x scriptname“命令来获得可执行权限):
tbash1.sh:
#!/bin/sh
source abc
echo "hello abc"
tbash2.sh:
#!/bin/bash
source abc
echo "hello abc"
tbash3.sh:
source abc
echo "hello abc"
三个脚本执行的结果:
[nsvc@localhost other]$ ./tbash1.sh
./tbash1.sh: line 2: abc: No such file or directory
注:当source命令执行有问题时,sh不再往下面执行。
[[email protected] other]$ ./tbash2.sh
./tbash2.sh: line 2: abc: No such file or directory
hello abc
注:当source命令执行有问题时,bash继续执行下面命令。
[[email protected] other]$ ./tbash3.sh
./tbash3.sh: line 1: abc: No such file or directory
hello abc
注:自身登录系统所在的shell是bash。所以,当source命令执行有问题时,bash继续执行下面命令。
如果将tbash1.sh改成:
echo "abc"
#!/bin/sh
source abc
echo "hello abc"
那么,执行结果是:
[[email protected] other]$ ./tbash1.sh
abc
./tbash1.sh: line 3: abc: No such file or directory
hello abc
也就是说,脚本忽略了第二行“#!/bin/sh",直接使用当前所在的shell(也就是bash)来解释脚本。
当把tbash1.sh改成:
#!/bin/sh
#!/bin/bash
source abc
echo "hello abc"
执行结果为:
[[email protected] other]$ ./tbash1.sh
./tbash1.sh: line 3: abc: No such file or directory
当执行完source命令时,并没有往下执行。说明,#!/bin/sh这一行起到作用了,但#!/bin/bash并没有起作用。在脚本中,除第一行外,脚本中所有以“#”开头的行都是注释。
2)#!后面的路径一定要正确,不正确会报错。
假如,我们把tbash1.sh中第一行的#!后面加了一个不存在的路径”/home/sh“:
#!/home/sh
source abc
echo "hello abc"
执行结果为:
[[email protected] other]$ ./tbash1.sh
-bash: ./tbash1.sh: /home/sh: bad interpreter: No such file ordirectory
系统会提示/home/sh的路径不存在。
3)如果一个脚本在第一行没有加上#!+shell路径这一行,那么,脚本会默认当前用户登录的shell,为脚本解释器。
在1)中,脚本tbash3.sh的执行结果,就是用当前自己登录的shell(bash)解释后的结果。我们通常所用的shell都是bash,如果哪天登录到sh,再使用以上类型的脚本,就会有问题。以下是自己登录到sh下,执行tbash3.sh的结果:
-sh-3.2$ ./tbash3.sh
./tbash3.sh: line 1: abc: 没有那个文件或目录
与1)中的执行结果是不一样的。
因此,大家应该养成脚本首行加上#!+shell路径的习惯。
4)/bin/sh相当于/bin/bash --posix
我们将脚本tbash1.sh改为:
#!/bin/bash --posix
source abc
echo "hello abc"
执行结果:
[[email protected] other]$ ./tbash1.sh
./tbash1.sh: line 2: abc: No such file or directory
与tbash1.sh原脚本执行的结果一样。
我们还可以以tbash3.sh为示例。
用以下命令来执行该脚本:
[[email protected] other]$ bash tbash3.sh
tbash3.sh: line 1: abc: No such file or directory
hello abc
[[email protected] other]$ sh tbash3.sh
tbash3.sh: line 1: abc: No such file or directory
[[email protected] other]$ bash --posix tbash3.sh
tbash3.sh: line 1: abc: No such file or directory
"bash tbash3.sh"表示使用bash来作为脚本解释器来执行tbash3.sh。同样,也可以使用如”sh脚本名“这样的命令,来用sh作为脚本解释器。
从结果可以看出,/bin/bash--posix与/bin/sh的执行结果相同。总结起来,sh跟bash的区别,实际上是bash有没开启posix模式的区别。遵守posix规范,可能包括,”当某行代码出错时,不继续往下执行。“
最后加上一点说明,每个脚本开头都使用"#!",#!实际上是一个2字节魔法数字,这是指定一个文件类型的特殊标记,在这种情况下,指的就是一个可执行的脚本。在#!之后,接一个路径名,这个路径名指定了一个解释脚本命令的程序,这个程序可以是shell,程序语言或者任意一个通用程序。
#!/bin/bash是指此脚本使用/bin/bash来解释执行。
其中,#!是一个特殊的表示符,其后,跟着解释此脚本的shell路径。
bash只是shell的一种,还有很多其它shell,如:sh,csh,ksh,tcsh,...
我们可以通过以下一个示例来进行实验,了解#!/bin/bash的使用。
除第一行外,脚本中所有以“#”开头的行都是注释。
1)#!/bin/bash只能放在第一行,如果后面还有#!,那么只能看成是注释。
这里有三个脚本(脚本都要使用”chmod +x scriptname“命令来获得可执行权限):
tbash1.sh:
#!/bin/sh
source abc
echo "hello abc"
tbash2.sh:
#!/bin/bash
source abc
echo "hello abc"
tbash3.sh:
source abc
echo "hello abc"
三个脚本执行的结果:
[nsvc@localhost other]$ ./tbash1.sh
./tbash1.sh: line 2: abc: No such file or directory
注:当source命令执行有问题时,sh不再往下面执行。
[[email protected] other]$ ./tbash2.sh
./tbash2.sh: line 2: abc: No such file or directory
hello abc
注:当source命令执行有问题时,bash继续执行下面命令。
[[email protected] other]$ ./tbash3.sh
./tbash3.sh: line 1: abc: No such file or directory
hello abc
注:自身登录系统所在的shell是bash。所以,当source命令执行有问题时,bash继续执行下面命令。
如果将tbash1.sh改成:
echo "abc"
#!/bin/sh
source abc
echo "hello abc"
那么,执行结果是:
[[email protected] other]$ ./tbash1.sh
abc
./tbash1.sh: line 3: abc: No such file or directory
hello abc
也就是说,脚本忽略了第二行“#!/bin/sh",直接使用当前所在的shell(也就是bash)来解释脚本。
当把tbash1.sh改成:
#!/bin/sh
#!/bin/bash
source abc
echo "hello abc"
执行结果为:
[[email protected] other]$ ./tbash1.sh
./tbash1.sh: line 3: abc: No such file or directory
当执行完source命令时,并没有往下执行。说明,#!/bin/sh这一行起到作用了,但#!/bin/bash并没有起作用。在脚本中,除第一行外,脚本中所有以“#”开头的行都是注释。
2)#!后面的路径一定要正确,不正确会报错。
假如,我们把tbash1.sh中第一行的#!后面加了一个不存在的路径”/home/sh“:
#!/home/sh
source abc
echo "hello abc"
执行结果为:
[[email protected] other]$ ./tbash1.sh
-bash: ./tbash1.sh: /home/sh: bad interpreter: No such file ordirectory
系统会提示/home/sh的路径不存在。
3)如果一个脚本在第一行没有加上#!+shell路径这一行,那么,脚本会默认当前用户登录的shell,为脚本解释器。
在1)中,脚本tbash3.sh的执行结果,就是用当前自己登录的shell(bash)解释后的结果。我们通常所用的shell都是bash,如果哪天登录到sh,再使用以上类型的脚本,就会有问题。以下是自己登录到sh下,执行tbash3.sh的结果:
-sh-3.2$ ./tbash3.sh
./tbash3.sh: line 1: abc: 没有那个文件或目录
与1)中的执行结果是不一样的。
因此,大家应该养成脚本首行加上#!+shell路径的习惯。
4)/bin/sh相当于/bin/bash --posix
我们将脚本tbash1.sh改为:
#!/bin/bash --posix
source abc
echo "hello abc"
执行结果:
[[email protected] other]$ ./tbash1.sh
./tbash1.sh: line 2: abc: No such file or directory
与tbash1.sh原脚本执行的结果一样。
我们还可以以tbash3.sh为示例。
用以下命令来执行该脚本:
[[email protected] other]$ bash tbash3.sh
tbash3.sh: line 1: abc: No such file or directory
hello abc
[[email protected] other]$ sh tbash3.sh
tbash3.sh: line 1: abc: No such file or directory
[[email protected] other]$ bash --posix tbash3.sh
tbash3.sh: line 1: abc: No such file or directory
"bash tbash3.sh"表示使用bash来作为脚本解释器来执行tbash3.sh。同样,也可以使用如”sh脚本名“这样的命令,来用sh作为脚本解释器。
从结果可以看出,/bin/bash--posix与/bin/sh的执行结果相同。总结起来,sh跟bash的区别,实际上是bash有没开启posix模式的区别。遵守posix规范,可能包括,”当某行代码出错时,不继续往下执行。“
最后加上一点说明,每个脚本开头都使用"#!",#!实际上是一个2字节魔法数字,这是指定一个文件类型的特殊标记,在这种情况下,指的就是一个可执行的脚本。在#!之后,接一个路径名,这个路径名指定了一个解释脚本命令的程序,这个程序可以是shell,程序语言或者任意一个通用程序。
The customized MATLAB function is to convert a rotation vector to a rotation matrix.function [rotation_matrix] = Rodrigues( rotation_vector )% Convert a rotation vector to a rotation matr...
清朗天空感受法治新生态刑侦破案、追捕罪犯、威武正气,一提起警察,大家脑海里往往会浮现出这样的形象。可在公安队伍里有这样一群人,他们虽不在一线作战单位,案件的第一现场却总是少不了他们的身影。他们不是基层所队民警,足迹却踏遍了辖区每个角落。他们没有记者证,但他们录像摄影、图片编辑、撰写稿件却样样在行,他们就是宣传民警。台江公安分局的陈宇航,就是一名活跃在公安战线上的宣传民警。他随警作战,为警而歌。从“...
目录1.前言2.实践代码(以下操作都在WIN7系统)2.1环境背景2.2环境搭建 2.2.1启动zookeeper(因为kafka依赖zookeeper) 2.2.2启动kafka 2.2.3启动elasticsearch 2.2.4启动logstash 2.2.5启动kibana 2.2....
任何数据类型想在网络中进行传输,都得经过编解码转换成字节流在netty中,服务端和客户端进行通信的其实是下面这样的程序 ---编码--> 网络网络 ---解码--> 程序对应服务端:入站数据, 经过解码器解码后给后续的handler使用出站数据, 结果编码器编码成字节流给在网络上传播在netty中的编码器其实就是一个handler,回想一下,无论是编写服务...
1.用Shell编程,判断一文件是不是字符设备文件,如果是将其拷贝到 /dev 目录下。参考程序:#!/bin/sh FILENAME= echo “Input file name:” read FILENAME if [ -c "$FILENAME" ] then cp $FILENAME /dev fi 2.设计一个shell程序,添加一个新组为clas...
1. read_csv函数的定义pd.read_csv(filepath_or_buffer: ‘FilePathOrBuffer’,sep=<no_default>,delimiter=None,header=‘infer’,names=<no_default>,index_col=None,usecols=None,squeeze=False,prefix=<no_default>,mangle_dupe_cols=True,dtype: ‘
dijikstra算法之优化版在上一个博客中的dijikstra最短路算法,虽然流程简单,但是由于使用邻接表的方式存储数据,空间复杂度(n^2)实在不理想,时间复杂度同样不佳。。。。在acm比赛中若不加以优化,往往超时无疑。为解决这个问题,在实际应用或比赛中常常使用优先队列优化。如下是我写的dijikstr算法优先队列优化版。用于自己日后复习和分享知识用,若有错误或不足之处请留言。dijik...
最近,北大学霸的LeetCode刷题笔记在GitHub上疯传!已经有不少人靠它手撕算法题,拿下了字节、腾讯等大厂offer!△1个月200道LeetCode无压力△手撕1800道算法题不问不知道,这份刷题笔记来自FB高级架构师、ACM金牌选手令狐冲之手。令狐老师在刷题和打ACM比赛中总结出了经验和套路,又疯狂爆肝3个月,对面试中的常考算法知识点给出通用解题思路和代码模板,已经有不少人通过这份小抄逆...
getWindow.setFlags()接着整理webview 中播放视频所用到的一些参数。 getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); 这段代码会让整个窗体全屏。 getWindow() 是Activity 中的一个方
这里只讲数据分析常用的图形绘制,至于复杂的图形不在本篇讨论范围,讲到的几个图形基本满足数据分析过程的要求,至于汇报材料或者其他的高质量图形,以后再另外写关于ggplot2的简单使用。 python的绘图工具主要是matplotlib,这里不讲复杂的使用,只讲简单的使用。使用matplotlib绘图有两种方法: 1.matplotlib绘图,指定参数data=DataFrame或Series 2
高通平台学习—前言从今天开始转向高通平台,希望能够记录下学习过程中遇到的点点滴滴,供以后复习查阅。
WPF文字方块 其实我们接着上次讲的课。 我们先拖个textBox到窗体中,给他字的背景色上一幅图画。 <TextBox Margin="0,52,16,69" Name="textBox1" FontSize="36" Background="Yellow" BorderBrush="Red" BorderThickness="7" ...