免费注册 查看新帖 |

Chinaunix

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

shell 下编程时遇到的问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2003-11-01 18:27 |只看该作者 |倒序浏览
本人使用的是REDHAT LINUX 9 PERSONAL,当在shell下运行单个命令时,一起正常,但是如果创建脚本来运行时,总是显示:command not found,无论是创建 sed,awk等等,均如此,即使在脚本的第一行,即: #!/bin/awk ,无论怎么更改路径也没用(根据whereis name,所查的几个路径)
请问这个问题应如何解决?希望能得到帮助,谢谢!

论坛徽章:
0
2 [报告]
发表于 2003-11-01 18:35 |只看该作者

shell 下编程时遇到的问题

运行脚本的时候是否切换了用户?
总感觉还是路径的问题。
#!/bin/awk是否是个awk脚本,需要awk调用?

论坛徽章:
0
3 [报告]
发表于 2003-11-01 19:28 |只看该作者

shell 下编程时遇到的问题

没有切换用户,我一直是使用 root 用户名登陆的。需要awk调用。

论坛徽章:
0
4 [报告]
发表于 2003-11-01 20:23 |只看该作者

shell 下编程时遇到的问题

[quote]原帖由 "jshen1971"]本人使用的是REDHAT LINUX 9 PERSONAL,当在shell下运行单个命令时,一起正常,但是如果创建脚本来运行时,总是显示:command not found,无论是创建 sed,awk等等,均如此,即使在脚本的第一行,即: #!/bin/awk ,?.........[/quote 发表:


#!/bin/xxx
的使用是为了保证此脚本在其他Unix系统下便于修改,以获得兼容?

你是怎么运行命令的?
#your-command
还是
#./your-command   
#../your-command

论坛徽章:
0
5 [报告]
发表于 2003-11-01 21:18 |只看该作者

shell 下编程时遇到的问题

都试过了,都不行

论坛徽章:
0
6 [报告]
发表于 2003-11-01 21:31 |只看该作者

shell 下编程时遇到的问题

把你的脚本贴出来看看行么?

论坛徽章:
0
7 [报告]
发表于 2003-11-02 15:17 |只看该作者

shell 下编程时遇到的问题

例如有如下一个grade.txt文件:
M.Tansley   05/99    48311   Green    8    40    44
J.Lulu      06/99    48317   green    9    24    26
P.Bunny     02/99    48      Yellow   12   35    28
J.Troll     07/99    4842    Brown-3  12   26    26
L.Tansley   05/99    4712    Brown-2  12   30    28
其中$1:名字;$2:升段日期;$3:学生序号;$4:腰带级别;$5:年龄;$6:目前比赛积分;$7:比赛最高分。现创建一个student_tot.awk脚本,结果是要将学生级别相加,即tot+=$6),文本如下:
#!/bin/awk -f
# all comment lines must start with a hash '#'
# name:student_tot.awk
# to call:student_tot.awk grade.txt
# print total and average of club student points
# print a header first
BEGIN{
print "Student  Date    Member NO.  Grade   Age    Points    Max"
print "Name     Joined                                 Gained  Point    Available"
print "========================================================================="

}
# let's add the scores of points gained
(tot+=$6)

# finished processing now let's print the total and average point
END{print "Club student total points :" tot
  print "Average Club Student points:" tot/NR}

执行时,首先对脚本文件加入了可执行权限 chmod u+x student_tot.awk
然后执行:student_tot.awk grade.txt
结果显示:bash: student_tot.awk: command not found
开始以为是路径不对,随后用 whereis awk 命令,得到下面几个路径:
/bin/awk
/usr/bin/awk
/usr/libexec/awk
/usr/share/awk
/usr/share/man/man1/awk.1.gz
但在更改了路径后,依然显示:command not found
随后在使用 sed,sh 等时,发现都是如此,请问这到底是怎么回事?应该怎么去解决?否则的话,我就只能在 shell 下使用命令来操作,而无法利用创建脚本来执行,极不方便.
另外还想请教一下:
1.在 UNIX/Linux 下的几种编程语言中,一般常用的是哪几种?因为在菜单里有很多中,不知道应选哪种.
2.在众多的报刊杂志中,有没有专门面向 UNIX/Linux 报刊杂志?

论坛徽章:
0
8 [报告]
发表于 2003-11-02 22:29 |只看该作者

shell 下编程时遇到的问题

Please try ./student_tot.awk grade.txt . Maybe Command not found means can not find student_tot.awk. or try "awk student_tot.awk grade.txt".

论坛徽章:
0
9 [报告]
发表于 2003-11-02 23:57 |只看该作者

shell 下编程时遇到的问题

你当前工作目录在哪?

登录身份?

你的.bash里PATH中有没有如/bin/awk?

你好像在用bash来执行awk脚本,   ./awk yourcommand

论坛徽章:
33
荣誉会员
日期:2011-11-23 16:44:17天秤座
日期:2014-08-26 16:18:20天秤座
日期:2014-08-29 10:12:18丑牛
日期:2014-08-29 16:06:45丑牛
日期:2014-09-03 10:28:58射手座
日期:2014-09-03 16:01:17寅虎
日期:2014-09-11 14:24:21天蝎座
日期:2014-09-17 08:33:55IT运维版块每日发帖之星
日期:2016-04-17 06:23:27操作系统版块每日发帖之星
日期:2016-04-18 06:20:00IT运维版块每日发帖之星
日期:2016-04-24 06:20:0015-16赛季CBA联赛之天津
日期:2016-05-06 12:46:59
10 [报告]
发表于 2003-11-03 09:41 |只看该作者

shell 下编程时遇到的问题

第一行该是"#!/bin/bash"吧?
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP