博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
为什么需要在脚本文件的开头加上#!/ bin / bash?
阅读量:2378 次
发布时间:2019-05-10

本文共 3026 字,大约阅读时间需要 10 分钟。

本文翻译自:

I have made scripts before and they all ran fine without this at the beginning. 之前我已经制作了脚本,并且在开始时它们都运行良好。 What's the point of putting it in? 把它放进去有什么意义? Would things be any different? 会有什么不同吗?

Also, how do you pronounce # ? 另外,你怎么发音# I know that ! 我知道! is pronounced as "bang." 发音为“bang”。

How is #! 怎么#! pronounced? 发音?


#1楼

参考:


#2楼

It can be useful to someone that uses a different system that does not have that library readily available. 对于使用不具有该库的不同系统的人来说,它可能是有用的。 If that is not declared and you have some functions in your script that are not supported by that system, you should declare #/bin/bash. 如果未声明并且您的脚本中有一些该系统不支持的函数,则应声明#/ bin / bash。 I've ran into this problem before at work and now I just include it as a practice. 我在工作之前遇到过这个问题,现在我只是把它作为一种练习。


#3楼

Also you will see some other parameters after #!/bin/bash, for example 例如,您还会在#!/ bin / bash之后看到一些其他参数

#!/bin/bash -v -x
read this to get more idea. 阅读本文以获得更多想法。
.


#4楼

It's a convention so the *nix shell knows what kind of interpreter to run. 这是一个约定,所以* nix shell知道要运行什么样的解释器。

For example, older flavors of ATT defaulted to sh (the Bourne shell), while older versions of BSD defaulted to csh (the C shell). 例如,较旧版本的ATT默认为sh (Bourne shell),而较旧版本的BSD默认为csh (C shell)。

Even today (where most systems run bash, the "Bourne Again Shell" ), scripts can be in bash, python, perl, ruby, PHP, etc, etc. For example, you might see #!/bin/perl or #!/bin/perl5 . 即使在今天(大多数系统运行bash, “Bourne Again Shell” ),脚本也可以是bash,python,perl,ruby,PHP等等。例如,你可能会看到#!/bin/perl#!/bin/perl5

PS: The exclamation mark ( ! ) is affectionately called "bang" . PS:感叹号( ! )被亲切地称为“爆炸” The shell comment symbol ( # ) is sometimes called "hash" . shell注释符号( # )有时称为“哈希”

PPS: Remember - under *nix, associating a suffix with a file type is merely a convention , not a "rule" . PPS:记住 - 在* nix下,将后缀与文件类型相关联仅仅是一种约定 ,而不是“规则” An executable can be a binary program, any one of a million script types and other things as well. 可执行文件可以是二进制程序,也可以是一百万种脚本类型中的任何一种。 Hence the need for #!/bin/bash . 因此需要#!/bin/bash


#5楼

The operating system takes default shell to run your shell script. 操作系统使用默认shell来运行shell脚本。 so mentioning shell path at the beginning of script, you are asking the OS to use that particular shell. 所以在脚本开头提到shell路径,你要求OS使用那个特定的shell。 It is also useful for . 它对于也很有用。


#6楼

Every distribution has a default shell. 每个发行版都有一个默认shell。 Bash is the default on the majority of the systems. Bash是大多数系统的默认设置。 If you happen to work on a system that has a different default shell, then the scripts might not work as intended if they are written specific for Bash. 如果您碰巧在具有不同默认shell的系统上工作,那么如果脚本是针对Bash编写的,则脚本可能无法正常工作。

Bash has evolved over the years taking code from ksh and sh . 多年来,Bash从kshsh获取代码。

Adding #!/bin/bash as the first line of your script, tells the OS to invoke the specified shell to execute the commands that follow in the script. 添加#!/bin/bash作为脚本的第一行,告诉操作系统调用指定的shell来执行脚本中的命令。

#! is often referred to as a "hash-bang", "she-bang" or "sha-bang". 通常被称为“哈希砰”,“嘻嘻”或“沙梆”。

转载地址:http://pyexb.baihongyu.com/

你可能感兴趣的文章
HDFS 回收站
查看>>
hadoop 完全分布式HA高可用集群(手工切换)搭建
查看>>
hadoop 完全分布式HA高可用集群(自动切换)搭建
查看>>
Hbase shell常见命令
查看>>
看看这同一句sql,scan index占用的资源大了很多!!
查看>>
couldn't set locale correctly报错解决
查看>>
回收基表的空间,造成物化视图只刷新了一部分数据
查看>>
ORA-12052,不能建立快速刷新物化视图的解决
查看>>
物化视图comlete刷新会产生大量的日志
查看>>
Mysql cluster slave server的自动检测与修复
查看>>
solaris同步时钟
查看>>
mysql升级
查看>>
V$sql_text v$sqlarea v$sql 的区别
查看>>
Redis 集群功能说明
查看>>
linux 下 free的用法
查看>>
oracle11gR2在RedHat5上前期安装配置脚本
查看>>
sar的用法
查看>>
Cocos2dx3.2从零开始【四】继续。
查看>>
Unable to execute dex: Multiple dex files define 解决方法
查看>>
Cocos2dx3.2从零开始【五】
查看>>