在Bash脚本中,第一行的
#!/bin/bash
是指定脚本需要运行的解释器为Bash。如果使用#!/bin/sh
则默认使用系统shell作为脚本解释器。#!/bin/bash
是指定脚本需要运行的解释器为Bash。如果使用#!/bin/sh
则默认使用系统shell作为脚本解释器。#!/bin/sh — Execute the file using sh, the Bourne shell, or a compatible shell
#!/bin/csh — Execute the file using csh, the C shell, or a compatible shell
#!/usr/bin/perl -T — Execute using Perl with the option for taint checks
#!/usr/bin/php — Execute the file using the PHP command line interpreter
#!/usr/bin/python -O — Execute using Python with optimizations to code
#!/usr/bin/ruby — Execute using Ruby
#!/bin/ksh
#!/bin/awk
#!/bin/expect
#!
时,这被称为shebang。如果您的文件以#!/path/to/something
开头,则标准是运行something
并将文件的其余部分作为输入传递给该程序。#!/bin/bash
、#!/bin/sh
甚至#!/bin/zsh
之间的区别在于使用bash、sh或zsh程序来解释文件的其余部分。bash
和sh
只是不同的程序,传统上而言,在某些Linux系统上,它们是相同程序的两个副本。在其他Linux系统上,sh
是指向dash
的链接,在传统的Unix系统(Solaris,Irix等)上,bash
通常是与sh
完全不同的程序。#!/usr/bin/python
, #!/usr/bin/perl
, 或者甚至是 #!/usr/local/bin/my_own_scripting_language
。sh
兼容模式。如果我们深入研究 Solaris、Aix、HPUX、Ultrix、SCO 等系统,每个系统都会有自己的默认 shell,并且会有 sh
模拟(以保持 POSIX 兼容性)。 - ocodo
#!/bin/bash
和#!/bin/sh
之间有什么区别吗? - Raptor#!/bin/bash
表示在 bash 中运行此脚本。#!/bin/sh
表示在sh
中运行此脚本,它是默认的 Unix shell,可能是 bash 或其他变体,如 ksh、dash、zsh 等。 - Karthik T#!
中使用。你可以尝试#!/usr/bin/firefox
,甚至如果你有一个位于路径/path/to/script
的脚本myscript
,那么#!/path/to/script/myscript
也可以工作。在这种情况下,myscript
将与shebang行中给出的参数一起启动,并且还会包括启动它的文件的文件名。 - gniourf_gniourf