Bash shell Script


Outline
  1. 1. command line.md
  2. 2. execute.sh
  3. 3. main.rb

command line.md

1
2
3
4
5
6
7
# check bash path
$ which bash
=> /bin/bash
$ chmod +x compile.sh
$ ./compile.sh
$ chmod +x execute.sh
1
$ ./execute.sh -r -i tmp2/queries/query-5.xml -o ans -m tmp2/model-files -d tmp2/CIRB010

execute.sh

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/bin/bash
FEEDBACK=false
while getopts ri:o:m:d: option
do
case "${option}" in
r) FEEDBACK=true;;
i) INPUT=${OPTARG};;
o) OUTPUT=${OPTARG};;
m) MODEL=${OPTARG};;
d) NTCIR=${OPTARG};;
esac
done
if $FEEDBACK
then
ruby main.rb -r-i $INPUT -o $OUTPUT -m $MODEL -d $NTCIR
else
ruby main.rb -i $INPUT -o $OUTPUT -m $MODEL -d $NTCIR
fi

main.rb

1
2
3
4
5
6
7
8
9
10
11
12
13
14
### read argument
require 'optparse'
$options = {}
OptionParser.new do |opts|
opts.on("-r") { |s| $options[:r] = true }
opts.on("-i", '-i INPUT', "input ") { |s| $options[:i] = s } # ./queries/origin/query-5.xml
opts.on("-o", '-o OUTPUT',"output") { |s| $options[:o] = s } # ans
opts.on("-m", '-m MODEL', "model ") { |s| $options[:m] = s } # ./model-files
opts.on("-d", '-d NTCIR', "ntcir ") { |s| $options[:d] = s } # /tmp2/CIRB010
end.parse!
$dir_queryfile = File.dirname($options[:i])
puts $options
### end read argument
. . .