免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
楼主: Pacific Yan
打印 上一主题 下一主题

help! please simplify this shell program! [复制链接]

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

help! please simplify this shell program!

你是手工输入的代码还是复制过去的,如果是手工输入的要确信没有输错。

你哪儿人啊,我看吃得到不

论坛徽章:
0
22 [报告]
发表于 2003-07-11 21:24 |只看该作者

help! please simplify this shell program!

I am in USA, but most likely I will visit China sometime this year.  Where are you?

Trust me I will invite you for sure!

I will take a look the code since I copy it to my UNIX machine.

论坛徽章:
0
23 [报告]
发表于 2003-07-11 21:28 |只看该作者

help! please simplify this shell program!

USA?????晕掉. 没戏了,除非你是来下面这两个地方之一
ChongQing ,HangZhou

你在unix下直接下载这个文件试试,我这儿执行没问题,不过我的系统是FreeBSD,不知道你的是什么.

ftp://bu.dns0755.net/test.sh

论坛徽章:
0
24 [报告]
发表于 2003-07-11 21:38 |只看该作者

help! please simplify this shell program!

I am in IBM Unix machine and use the korn shell which is required by this test.


ChongQing and HangZhou are beautiful city which I have never been there before.  Wuhan and Beijing are the only city I had lived ...


After meeting I will try again and see what happens.  Maybe it is a minor probelm.

论坛徽章:
0
25 [报告]
发表于 2003-07-11 21:42 |只看该作者

help! please simplify this shell program!

korn shell没用过.       
没有sh吗?

$ ls /bin/sh

论坛徽章:
0
26 [报告]
发表于 2003-07-11 21:58 |只看该作者

help! please simplify this shell program!

Now it works for me, but the output isn't in one line.  

It should be like this:  $ Sunday Thursday Friday

By the way, thank you a lot and keep in touch!


$ cat >test.sh
#!/usr/bin/ksh
if [ $# -ne 1 ];then exit 1;fi
if [ $1 -ge 1 ] && [ $1 -le 9999 ];then

da=0
for st in Sunday Monday Tuesday Wednesday Thursday Friday Saturday;do
        eval str_$da=$st
        da=$(($da + 1))
done

mon=1
while [ $mon -le 12 ];do
        da=`cal $mon $1 |awk 'NR==3{loc=index($0,"1";print (loc-2)/3;exit}'`
        eval "count_$da=\$((\$count_$da+1))"
        mon=$(($mon + 1 ))
done

da=0
while [ $da -le 6 ];do
        eval dcn=\$count_$da
        if [ $dcn -eq 1 ];then
                eval "echo \"\$str_$da \""|awk 'BEGIN {OFS=" "; ORS=" "} {print $1} END {print "\n"}'
fi
        da=$(($da + 1))
done
echo
fi

$ test.sh 2003
Sunday
Thursday
Friday

论坛徽章:
0
27 [报告]
发表于 2003-07-11 22:03 |只看该作者

help! please simplify this shell program!

eval "echo \"\$str_$da \""|awk 'BEGIN {OFS=" "; ORS=" "} {print $1} END {print "\n"}'
this line failed. check it yourself.

论坛徽章:
0
28 [报告]
发表于 2003-07-11 22:13 |只看该作者

help! please simplify this shell program!

You are right, this line failed, but it works in Compaq Tru64 and also IBM, but doesn't work in SunOS 5.8, why?

see the following example in Tru64 korn shell:

$ cat sorttest
Friday 1
Sunday 1
Thursday 1
Monday 2
Tuesday 2
Wednesday 2
Saturday 3

$ cat sorttest |awk 'BEGIN {OFS=" "; ORS=" "} {print $1} END {print "\n"}'
Friday Sunday Thursday Monday Tuesday Wednesday Saturday

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

help! please simplify this shell program!

是不是你的echo没有-n参数?你想用awk代替?

论坛徽章:
0
30 [报告]
发表于 2003-07-11 22:24 |只看该作者

help! please simplify this shell program!

END {print "\n"}
删掉这段应该可以了
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP