-1

I have a problem using this start.sh script. When I type ./start.sh, it doesn't work. I mean, it makes no errors but it does nothing.

When I open this file using VIM (I really want to upload the image, but I can't because I registered this site just few days ago) the lines from import sys,math,random to print '\n' are all colored red. After EOS, the color is normally shown. If I type # in front of cat, I mean, #cat <<EOS | python > target.txt, the colors are changed.

So I think this line:

cat <<EOS | python > target.txt

is wrong. How can I correct it?

#!/bin/sh

if [ "$1" = clean ]; then
rm -f *.log *.dat target.txt
exit
fi

num=1
length=1000
period=50

cat <<EOS | python > target.txt
import sys,math,random
funcs = [
lambda t : (0.8 * math.sin(t), 0.8 * math.cos(t)),
lambda t : (0.3 * math.sin(t), 0.3 * math.cos(t)),
lambda t : (0.8 * math.sin(3 * t), 0.8 * math.cos(t)),
lambda t : (0.8 * math.cos(t), 0.8 * math.sin(3 * t)),

lambda t : (0.4 * math.sin(2 * t) + 0.4, 0.8 * math.cos(t)),
lambda t : (0.4 * math.sin(2 * t) - 0.4, 0.8 * math.cos(t)),
lambda t : (0.8 * math.sin(2 * t), 0.4 * math.cos(t) + 0.4),
lambda t : (0.8 * math.sin(2 * t), 0.4 * math.cos(t) - 0.4),

lambda t : (0.4 * math.cos(t) + 0.4, 0.8 * math.sin(2 * t)),
lambda t : (0.4 * math.cos(t) - 0.4, 0.8 * math.sin(2 * t)),
lambda t : (0.8 * math.cos(t), 0.4 * math.sin(2 * t) + 0.4),
lambda t : (0.8 * math.cos(t), 0.4 * math.sin(2 * t) - 0.4),

lambda t : (0.4 * math.sin(t) + 0.4, 0.8 * math.cos(t)),
lambda t : (0.4 * math.sin(t) - 0.4, 0.8 * math.cos(t)),
lambda t : (0.8 * math.sin(t), 0.4 * math.cos(t) - 0.4),
lambda t : (0.8 * math.sin(t), 0.4 * math.cos(t) + 0.4),

lambda t : (0.8 * math.sin(t), 0.8 * math.cos(2 * t)),
lambda t : (0.8 * math.sin(t), -0.8 * math.cos(2 * t)),
lambda t : (0.8 * math.cos(2 * t), 0.8 * math.sin(t)),
lambda t : (-0.8 * math.cos(2 * t), 0.8 * math.sin(t)),

lambda t : (0.3 * math.sin(t) + 0.5, 0.3 * math.cos(t) + 0.5),
lambda t : (0.3 * math.sin(t) + 0.5, 0.3 * math.cos(t) - 0.5),
lambda t : (0.3 * math.sin(t) - 0.5, 0.3 * math.cos(t) + 0.5),
lambda t : (0.3 * math.sin(t) - 0.5, 0.3 * math.cos(t) - 0.5)
]
def gen_sigma():
sigma = [0.01, 0.05]
n = 0
while True:
    yield sigma[n % len(sigma)]
    n += 1
gen = gen_sigma()

for f in funcs:
sigma = gen.next()
for n in xrange($num):
    m = random.randint(0, 1000)
    for t in [x * ((2 * math.pi) / $period) for x in xrange(m, $length+m)]:
        print '\t'.join([str(x + random.gauss(0, sigma)) for x in f(t)])
    print '\n'
EOS

if [ x`which rnn-learn` == x ]; then
path1=../../src/rnn-learn/
else
path1=
fi
${path1}rnn-learn -c config.txt target.txt
Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278

1 Answers1

1

There is nothing self-evidently wrong with the script. The section that is marked in red is a 'here document' which runs from the line after the line containing <<EOS to the line containing just EOS. The here document is provided as standard input to Python, which writes its output to the file target.txt. The remainder of the script runs the rnn-learn command on the target.txt file, guided (I guess) by the configuration file config.txt.

When you put a # in front of the line containing the cat command, that becomes a comment, so the following lines are 'just shell script' — they aren't meaningful as shell script, but vim would be hard pressed to know that (it's an editor!). So, it changes the colour of the lines because they aren't part of a here document any more.

The cat really isn't necessary. The line could have been written as:

python > target.txt <<EOS
Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278