shell脚本的#!

53 篇文章 0 订阅
14 篇文章 0 订阅

摘自shell FAQ


#! 我不是注释,我是引用解释。

A1:bash脚本开始总少不了一句

[cpp]  view plain  copy
 print ?
  1. #! /bin/bash  
这行是脚本的 sha-bang line(sharp (#) and bang (!))是要告诉大家这个脚本是由 /bin/bash来解释的

参考( Mendel Cooper 的 Advanced Bash Scripting Guide  ,第一章第二部分  Chapter 2. Starting Off With a Sha-Bang

The sha-bang ( #![1] at the head of a script tells your system that this file is a set of commands to be fed to the command interpreter indicated. The #! is actually a two-byte [2] magic number, a special marker that designates a file type, or in this case an executable shell script (type man magic for more details on this fascinating topic). Immediately following the sha-bang is a path name. This is the path to the program that interprets the commands in the script, whether it be a shell, a programming language, or a utility. This command interpreter then executes the commands in the script, starting at the top (the line following the sha-bang line), and ignoring comments. [3]

#!叫做Magic number(幻数、魔数。含义为当一个普通字符含有特殊意义时就叫幻数), #! 用来指定解释脚本的程序,可以是 Shell,也可以是其他程序。

[cpp]  view plain  copy
 print ?
  1. #!/bin/php  
  2. #!/bin/expect  
  3. #!/bin/perl  
  4. ......  

1) 如果shell脚本的第一个非空白字符不是“ #”,则它会使用Bourne shell。
2) 如果shell脚本的第一个非空白字符是“ #”,但不以“# !”开头时,则它会使用C shell。
3) 如果shell脚本以“# !”开头,则“ # !”后面所跟的字符串就是所使用的shell的绝对路径名。Bourne shell的路径名称为/bin/sh ,而C 外壳则为/bin/csh。


  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值