4 <h1><a name=
"shell_script" id=
"shell_script">Shell Script
</a></h1>
9 <a href=
"http://en.wikipedia.org/wiki/Shell_script" class=
"interwiki iw_wp" title=
"http://en.wikipedia.org/wiki/Shell_script">Shell Script
</a>.
11 <div class=
"plugin_uparrow">
12 <a href=
"#" title=
"Back to top">
13 <img src=
"lib/plugins/uparrow/images/tango-small.png" alt=
"Back to top"/>
18 <!-- SECTION "Shell Script" [1-63] -->
19 <h2><a name=
"examples" id=
"examples">Examples
</a></h2>
22 <dt><a href=
"/~kssilveira/site/doku.php?do=export_code&id=main:shell_script&codeblock=0" title=
"Download Snippet" class=
"mediafile mf_sh">run.sh
</a></dt>
23 <dd><pre class=
"code file bash"><span class=
"co0">#!/bin/bash
</span>
24 <span class=
"re2">dir_names
</span>=
<span class=
"br0">(</span><span class=
"st0">"tcp/null
"</span> <span class=
"st0">"tcp/sort
"</span> <span class=
"st0">"udp/null
"</span><span class=
"br0">)</span>
25 <span class=
"kw1">for
</span> d
<span class=
"kw1">in
</span> <span class=
"br0">{</span>0.
.2<span class=
"br0">}</span>
26 <span class=
"kw1">do
</span>
27 <span class=
"re2">dir_name
</span>=
<span class=
"co1">${dir_names[$d]}
</span>
28 <span class=
"kw3">echo
</span> <span class=
"st0">"<span class=
"es2">$dir_name
</span>"</span>
29 <span class=
"kw2">mv
</span> <span class=
"st0">"<span class=
"es2">$dir_name
</span>/out.txt
"</span> <span class=
"st0">"<span class=
"es2">$dir_name
</span>/out.bak.txt
"</span>
30 <span class=
"kw1">for
</span> j
<span class=
"kw1">in
</span> <span class=
"br0">{</span>0.
.3<span class=
"br0">}</span>
31 <span class=
"kw1">do
</span>
32 <span class=
"co0">#echo
"$j
"</span>
33 <span class=
"kw1">for
</span> i
<span class=
"kw1">in
</span> <span class=
"br0">{</span>0.
.9<span class=
"br0">}</span>
34 <span class=
"kw1">do
</span>
35 <span class=
"co0">#echo
"$i
"</span>
36 <span class=
"kw1">if
</span> <span class=
"br0">[</span> <span class=
"st0">"<span class=
"es2">$d
</span>"</span> =
<span class=
"st0">"8"</span> <span class=
"br0">]</span> <span class=
"sy0">||
</span> <span class=
"br0">[</span> <span class=
"st0">"<span class=
"es2">$d
</span>"</span> =
<span class=
"st0">"9"</span> <span class=
"br0">]</span>
37 <span class=
"kw1">then
</span>
38 <span class=
"kw3">cd
</span> <span class=
"st0">"<span class=
"es2">$dir_name
</span>"</span>
39 java Client
143.54.12.150:
<span class=
"nu0">808</span><span class=
"st0">"<span class=
"es2">$d
</span>"</span> <span class=
"sy0">>></span> <span class=
"st0">"out.txt
"</span>
40 <span class=
"kw3">cd
</span> <span class=
"st0">"../../
"</span>
41 <span class=
"kw1">else
</span>
42 .
<span class=
"sy0">/
</span><span class=
"st0">"<span class=
"es2">$dir_name
</span>/client
"</span> 143.54.12.150 <span class=
"nu0">808</span><span class=
"st0">"<span class=
"es2">$d
</span>"</span> <span class=
"sy0">>></span> <span class=
"st0">"<span class=
"es2">$dir_name
</span>/out.txt
"</span>
43 <span class=
"kw1">fi
</span>
44 <span class=
"kw1">done
</span>
45 <span class=
"kw2">sleep
</span> 60
46 <span class=
"kw1">done
</span>
47 .
<span class=
"sy0">/
</span>calc.rb
<span class=
"st0">"<span class=
"es2">$dir_name
</span>/out.txt
"</span>
48 <span class=
"kw1">done
</span></pre>
51 <dt><a href=
"/~kssilveira/site/doku.php?do=export_code&id=main:shell_script&codeblock=1" title=
"Download Snippet" class=
"mediafile mf_sh">run_tests.sh
</a></dt>
52 <dd><pre class=
"code file bash"><span class=
"co0">#!/bin/bash
</span>
53 <span class=
"kw1">for
</span> prog
<span class=
"kw1">in
</span> <span class=
"sy0">*
</span>.pico
54 <span class=
"kw1">do
</span>
55 <span class=
"kw3">echo
</span> <span class=
"st0">"<span class=
"es2">$prog
</span>"</span>
56 <span class=
"re2">prog_name
</span>=
<span class=
"co1">${prog%\.*}
</span>
57 .
<span class=
"sy0">/
</span>run_test.sh
<span class=
"st0">"<span class=
"es2">$prog_name
</span>"</span>
58 <span class=
"kw1">done
</span></pre>
61 <dt><a href=
"/~kssilveira/site/doku.php?do=export_code&id=main:shell_script&codeblock=2" title=
"Download Snippet" class=
"mediafile mf_sh">run_test.sh
</a></dt>
62 <dd><pre class=
"code file bash"><span class=
"co0">#!/bin/bash
</span>
63 <span class=
"kw1">if
</span> <span class=
"kw3">test
</span> <span class=
"re4">$#
</span> <span class=
"re5">-ne
</span> 1
64 <span class=
"kw1">then
</span>
65 <span class=
"kw3">echo
</span> <span class=
"st0">"usage: $
0 program_name
"</span>
66 <span class=
"kw3">echo
</span> <span class=
"st0">"given: $*
"</span>
67 <span class=
"kw1">else
</span>
68 <span class=
"re2">prog_name
</span>=$
1
69 .
<span class=
"sy0">/
</span>..
<span class=
"sy0">/
</span>..
<span class=
"sy0">/
</span>src
<span class=
"sy0">/
</span>pico
<span class=
"re5">-o
</span> <span class=
"st0">"<span class=
"es2">$prog_name
</span>.tac
"</span> <span class=
"st0">"<span class=
"es2">$prog_name
</span>.pico
"</span>
70 <span class=
"kw1">fi
</span></pre>
72 <div class=
"plugin_uparrow">
73 <a href=
"#" title=
"Back to top">
74 <img src=
"lib/plugins/uparrow/images/tango-small.png" alt=
"Back to top"/>
79 <!-- SECTION "Examples" [64-962] -->
80 <h2><a name=
"books" id=
"books">Books
</a></h2>
84 <a href=
"/~kssilveira/site/lib/exe/fetch.php?media=main:canivete-shell.pdf" class=
"media mediafile mf_pdf" title=
"main:canivete-shell.pdf">Canivete Shell
</a>
87 <div class=
"plugin_uparrow">
88 <a href=
"#" title=
"Back to top">
89 <img src=
"lib/plugins/uparrow/images/tango-small.png" alt=
"Back to top"/>
94 <!-- SECTION "Books" [963-] -->