免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 7304 | 回复: 17
打印 上一主题 下一主题

shell文件首行,写#!/bin/bash,运行时出错 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-03-30 12:14 |只看该作者 |倒序浏览
我使用Fedora 14,在一个Shell文件里,我开头写入:
#!/bin/bash
运行这个文件时,即出现:line 1: #!/bin/bash  没有那个文件或目录。

我以前用Fedora Core 4.0,脚本文件都是以#!/bin/bash开头的呀。难道政策变了?

论坛徽章:
0
2 [报告]
发表于 2011-03-30 12:16 |只看该作者
回复 1# cutecactus


    echo $SHELL
which sh

论坛徽章:
2
技术图书徽章
日期:2013-10-30 14:37:252015年亚洲杯之伊朗
日期:2015-04-30 13:37:02
3 [报告]
发表于 2011-03-30 12:20 |只看该作者
bash 不在那个目录。有点奇怪。。

论坛徽章:
33
ChinaUnix元老
日期:2015-02-02 08:55:39CU十四周年纪念徽章
日期:2019-08-20 08:30:3720周年集字徽章-周	
日期:2020-10-28 14:13:3020周年集字徽章-20	
日期:2020-10-28 14:04:3019周年集字徽章-CU
日期:2019-09-08 23:26:2519周年集字徽章-19
日期:2019-08-27 13:31:262016科比退役纪念章
日期:2022-04-24 14:33:24
4 [报告]
发表于 2011-03-30 12:48 |只看该作者
find一下你的bash在哪个目录下

论坛徽章:
0
5 [报告]
发表于 2011-03-30 12:49 |只看该作者
找到原因了,政策的确变了,
#!/bin/bash
需要写成
#! /bin/bash
有个空格,以前允许没有空格的。{:3_192:}

论坛徽章:
0
6 [报告]
发表于 2011-03-30 13:03 |只看该作者
学习了,还有这个空格的限制

论坛徽章:
1
2015年辞旧岁徽章
日期:2015-03-03 16:54:15
7 [报告]
发表于 2011-03-30 13:06 |只看该作者
原来是不推荐不加空格,现在直接不允许了??

论坛徽章:
0
8 [报告]
发表于 2011-03-30 13:30 |只看该作者
诶 有这事? 没有遇到过矣。。。

论坛徽章:
7
荣誉版主
日期:2011-11-23 16:44:17子鼠
日期:2014-07-24 15:38:07狮子座
日期:2014-07-24 11:00:54巨蟹座
日期:2014-07-21 19:03:10双子座
日期:2014-05-22 12:00:09卯兔
日期:2014-05-08 19:43:17卯兔
日期:2014-08-22 13:39:09
9 [报告]
发表于 2011-03-30 15:28 |只看该作者
Blank after #! required?

There is a rumor, that a very few and very special, earlier Unix versions (particularly 4.2BSD derivatives) require you to separate the "#!" from the following path with a blank.
You may also read, that (allegedly) such a kernel parses "#! /" as a 32-bit (long) magic. But it turns out that it is virtually impossible to find a Unix which actually required this.

4.2BSD in fact doesn't require it, although previous versions of the GNU autoconf tutorial wrongly claimed this ("10. Portable Shell Programming", corrected with release 2.64, 2009-07-26).
But instead, see 4.2BSD, /usr/src/sys/sys/kern_exec.c (the first regular occurence). A blank is accepted but not required.
All this pointed out by Gunnar Ritter in <3B5B0BA4.XY112IX2@bigfoot.de> (and thanks to the new Caldera license, the code can be cited here now.)

Instead, the origin of this myth "of the required blank" might be a particular release of 4.1 BSD: There is a manpage in a "4.1.snap" snapshot of 4.1BSD
on the CSRG CDs, /usr/man/man2/exec.2 (4/1/81), where a space/tab after the #! is mentioned as mandatory. However, this is not true: the source itself remained unchanged.
(Hint to the existence of such a manpage from Bruce Barnett in <ae3m9l$rti$0@208.20.133.66>).

It's not clear whether this is a bug or confusion in documentation or if Berkeley planned to modify the BSD source but eventually did not.

DYNIX is mentioned in the autoconf documentation, too. It's unclear if this variant might have implemented it in a few releases
(perhaps following the abovementioned manual page). At least Dynix 3.2.0 or Dynix PTS 1.2.0 were actually 4.2 BSD derived and did not require the blank

I asked David MacKenzie, the author of the autoconf documentation, about the actual origin of the autoconf note.
But unfortunately neither the reporting author nor the very system are recorded anymore.

Even intensive search of usenet archives didn't reveal any further hints to me.

论坛徽章:
5
2015年辞旧岁徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:50:282015年亚洲杯之朝鲜
日期:2015-03-13 22:47:33IT运维版块每日发帖之星
日期:2016-01-09 06:20:00IT运维版块每周发帖之星
日期:2016-03-07 16:27:44
10 [报告]
发表于 2011-03-30 16:13 |只看该作者
回复 9# r2007

久违了,学习了。
   
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP