LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 536|回复: 3

一个关于中文显示的问题

[复制链接]
发表于 2004-7-20 22:51:25 | 显示全部楼层 |阅读模式
其实标题有点不太合适,我昨天写Shell的时候遇到一个问题,代码如下:
echo "请输入密码:"
read passwd
...
但是运行的时候提示我说无法执行,具体意思大概就是什么无法编译的代码吧,"...cannot execute ..."

不过我在脚本的第一行随便加入了一个注释行,再执行就OK了,也就是说只要不把有中文的一行放在程序的首行就可以执行,反之就报错。我百思不得其解,希望大家帮忙。:help
发表于 2004-7-20 23:03:33 | 显示全部楼层
在shell script中,首行的信息狠重要!
一般的(比较规矩)的写法:
#!/bin/bash   
...
...
也就是说,告诉内核,用哪个shell来解释你的脚本!建议大家在写脚本的时候,还是按照规则去编写脚本文件.
这方面的知识,在精华区的教程和shell基础的文章都有介绍!,方便的时候,多看看,相信对大家有所帮助! :thank
发表于 2004-7-20 23:07:37 | 显示全部楼层
这是bash的bug吧。
请阅读一下bash相应代码便可知道答案。
发表于 2004-7-20 23:26:25 | 显示全部楼层
bug? 不会吧~,测试:
/home/lee#cat file
这是一个脚本
echo "这是一个脚本"
/home/lee#ll file
-rwxr-xr-x    1 lee      lee            33  7月 20 23:27 file
/home/lee#./file
./file: ./file: cannot execute binary file
/home/lee#ksh file
file[1]: 这是一个脚本: not found
这是一个脚本
/home/lee#bash file
file: file: cannot execute binary file
/home/lee#csh file
这是一个脚本: Command not found.
这是一个脚本

/home/lee#bash
/home/lee#./file
bash: ./file: cannot execute binary file
/home/lee#csh
[lee@linux ~]$ ./file
./file: ./file: cannot execute binary file
[lee@linux ~]$
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表