shell 脚本头文件 (#!/bin/sh vs #!/bin/csh) [英] shell-script headers (#!/bin/sh vs #!/bin/csh)

查看:70
本文介绍了shell 脚本头文件 (#!/bin/sh vs #!/bin/csh)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么所有的脚本文件都以

Why do all script files start with

#!/bin/sh

#!/bin/csh

需要吗?这样做的目的是什么?两者有什么区别?

Is that required? What's the purpose of this? And what's the difference between the two?

推荐答案

这被称为 Shebang:

http://en.wikipedia.org/wiki/Shebang_(Unix)

#!interpreter [可选参数]

#!interpreter [optional-arg]

shebang 仅在脚本具有执行权限时才相关(例如 chmod u+x script.sh).

A shebang is only relevant when a script has the execute permission (e.g. chmod u+x script.sh).

当 shell 执行脚本时,它将使用指定的解释器.

When a shell executes the script it will use the specified interpreter.

示例:

#!/bin/bash
# file: foo.sh
echo 1

$ chmod u+x foo.sh
$ ./foo.sh
  1

这篇关于shell 脚本头文件 (#!/bin/sh vs #!/bin/csh)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆