- 论坛徽章:
- 0
|
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 报刊杂志? |
|