第一个SHELL脚本
时间:2010-07-06 来源:frostmourn716
欢迎访问我的新博客:http://troychengspace.appspot.com/2010/07/5/linux14.html
软件学报的论文修改的截止日期快到了,我才刚刚开始修改,晕,被逼无奈开始熬夜.....本来不用这么惨的,但是很多事情共同导致了现在的情况就是熬夜,比如说,租的房子如果没有坏的话,比如说,如果Intel的网络好用的话,再比如说,如果我不是这么着急来Intel的话,这篇论文呢本该很快很从容的就修改好的,可是再假设也无法改变这个事实,现在只能窝在这个小小的实验室里面改了。
为了节省跑算法的时间,我计划把各种对比算法的运行以及结果统计写成一个脚本,然后让我那台辛苦的服务器没日没夜的跑,等明天上班回来看结果就行。虽然原来没有写过脚本,但是觉得这是很简单的一件事,虽然没写过,但是至少看过很多,想想应该不会很难。也是磨蹭了了一会儿8点钟开始写,中间碰到了不少问题,主要有两个,在此记录一下:
- Ubuntu 中默认的shell不是我们所常用的bin/sh,在定义数组的时候总是出各种毛病,查了挺多网页,最后把它改成!/bin/bash后好用。定义数组的格式为:array=(* * *)
- 运行命令的时候最好使用这种格式$( ........................ )
tcheng@node10:~/Antcolony/ACOTSP.V1.0$ vim runaco.sh
1 #!/bin/bash
2 # Here is the tsp instance data file
3 tsplib=(d198 lin318 pcb442 att532)
4 antnum=(198 318 442 532)
5 aconame=(ras mas acs)
6
7 #run the test
8 i=0
9 tspliblen=${#tsplib[*]}
10 aconamelen=${#aconame[*]}
11
12 #loop
13 while [ $i -lt $tspliblen ]; do
14 tspname=${tsplib[$i]}
15 tspfile="${tspname}.tsp"
16 echo "Loading tsp data file: $tspfile"
17
18 mkdir $tspname
19 echo "Create path ./$tspname"
20
21 echo "Enter path $tspname"
22 echo
23 cd $tspname
24
25 #loop for three aco algorithms
26 j=0
27 while [ $j -lt $aconamelen ]; do
28 algorithm=${aconame[$j]}
29 anttotal=${antnum[$i]}
30
31 echo "create path ./$algorithm"
32 mkdir $algorithm
33
34 echo "enter path $algorithm"
35 echo "----------------------------"
36 echo
37 cd $algorithm
38
39 echo "start to execute aco algorithm: ${algorithm} with ant number : ${anttotal}"
40 $(../../acotsp -r 25 -s 1500 -i ../../$tspfile -t 600 -m ${antnum[ $i]} -a 5 -b 2 -m $anttotal -e 0.02 -l 1 -q 0.2 > run.log)
41 echo "end algorithms: ${algorithm}"
42
43 echo "leave path $algorithm"
44 echo
45 echo "----------------------------"
46 cd ..
47 let j++
48 done
49
50 echo "leave path $tspname"
51 echo
52 cd ..
53 let i++
54 done

<img preview="http://pic.pdowncc.com/uploadimg/ico/2025/0523/1747993424374100.png" width="32" height="32" src="http://pic.pdowncc.com/uploadimg/ico/2025/0523/1747993424374100.png" alt="弓箭勇者最新版" />
飞行射击 下载
<img preview="http://pic.pdowncc.com/uploadimg/ico/2025/0523/1747993424374100.png" width="32" height="32" src="http://pic.pdowncc.com/uploadimg/ico/2025/0523/1747993424374100.png" alt="弓箭勇者最新版" />
飞行射击 下载
<img preview="http://pic.pdowncc.com/uploadimg/ico/2025/0523/1747993424374100.png" width="32" height="32" src="http://pic.pdowncc.com/uploadimg/ico/2025/0523/1747993424374100.png" alt="弓箭勇者最新版" />
飞行射击 下载- 4 <img preview="http://pic.pdowncc.com/uploadimg/ico/2025/0523/1747993424374100.png" width="32" height="32" src="http://pic.pdowncc.com/uploadimg/ico/2025/0523/1747993424374100.png" alt="弓箭勇者最新版" />下载73.78MB · 97℃
1970-01-01
- 5 <img preview="http://pic.pdowncc.com/uploadimg/ico/2025/0523/1747993424374100.png" width="32" height="32" src="http://pic.pdowncc.com/uploadimg/ico/2025/0523/1747993424374100.png" alt="弓箭勇者最新版" />下载43.7 MB · 94℃
1970-01-01
- 6 <img preview="http://pic.pdowncc.com/uploadimg/ico/2025/0523/1747993424374100.png" width="32" height="32" src="http://pic.pdowncc.com/uploadimg/ico/2025/0523/1747993424374100.png" alt="弓箭勇者最新版" />下载110.69MB · 95℃
1970-01-01