shebang_什么是Shebang Linux或Bash术语?

shebang

shebang

In computing shebang is characters consist of number sign and exclamation mark #!. There are alternative names like she-bang, hash-bang, pound-bang, or hash-piling. Shebang is generally used in script-like text to specify script interpreter or type.  Some languages omit # as comment mark but with ! there is a special meaning.

在计算shebang时,字符由数字符号和感叹号组成 #! 。 还有其他名称,例如she-bang,hash-bang,pound-bang或hash-piling。 Shebang通常用于类似脚本的文本中,以指定脚本解释器或类型。 一些语言省略#作为注释标记,但带有! 有一个特殊的意义。

舍邦语法 (Shebang Syntax)

Shebang is generally used with interpreter specification only and no optional argument is provided.

Shebang通常仅与解释器规范一起使用,并且未提供可选参数。

#!interpreter ARGUMENT

Here interpreter is the application used to interpret the following script. Most popular interpreters are Shell, Bash, Python, Perl, Php, etc.

解释器是用于解释以下脚本的应用程序。 最受欢迎的解释器是Shell,Bash,Python,Perl,Php等。

#!/bin/bash

echo "poftut.com"

Bash is the interpreter of the script. echo “poftut.com” will be interpreted as a bash script and will print “poftut.com” to the default output.

Bash是脚本的解释器。 echo“ poftut.com”将被解释为bash脚本,并将“ poftut.com”打印到默认输出。

向Shebang命令提供参数 (Providing Parameters To Shebang Command)

As we see in syntax section parameters can be provided to the specified interpreter. For example, it can be provided -x to enable debug in bash scripts like below.

正如我们在语法部分所看到的,可以将参数提供给指定的解释器。 例如,可以提供-x来启用bash脚本中的调试,如下所示。

#!/bin/bash -X

echo "poftut.com"

Shebang提供便携性 (Shebang Provides Portability)

Some operating system families process shebang differently. To make things more portable env technique can be used. This is useful if the specified interpreter path is different in different operating systems. Directly the path defined in the environment variable will be called.

某些操作系统系列对shebang的处理方式有所不同。 为了使事情更加便携,可以使用env技术。 如果指定的解释器路径在不同的操作系统中不同,这将很有用。 将直接调用环境变量中定义的路径。

#!/usr/bin/env bash 
 
echo "poftut.com"
LEARN MORE  How To Check If File Exists In Linux Bash?
了解更多如何检查Linux Bash中是否存在文件?

翻译自: https://www.poftut.com/what-is-shebang-linux-or-bash-term/

shebang

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值