
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"
翻译自: https://www.poftut.com/what-is-shebang-linux-or-bash-term/
shebang