2013-02-07 70 views
-1

我在使用这个start.sh脚本时遇到问题。 当我输入 ./start.sh,它不起作用。 我的意思是,它没有任何错误,但它什么都不做。似乎错了shell脚本:cat

当我用VIM打开这个文件(我真的要上传的图片,但我可以,因为我只是前几天不注册这个网站) 从import sys,math,randomprint '\n'线条 所有红色。 EOS, 颜色正常显示。 如果我在cat前输入#,我的意思是,#cat <<EOS | python > target.txt,颜色发生了变化。

所以我觉得这行:

cat <<EOS | python > target.txt 

是错误的。我该如何纠正它?

#!/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 
+0

从哪里得到这个Python脚本包裹在Bourne Shell中?我建议你与作者核对。 – Johnsyweb

+0

如果我能做到,我做到了。但我无法与他联系。谢谢 – stacksmith

回答

1

脚本没有什么明显的错误。标记为红色的部分是'here document',它从包含<<EOS的行后面的行延伸到仅包含EOS的行。这里的文档是Python的标准输入,它将输出写入文件target.txt。脚本的其余部分在target.txt文件上运行rnn-learn命令,由配置文件config.txt引导(我猜)。

当你在包含cat命令行的前面放一个#,变成一个评论,所以下面的行“只是shell脚本” - 他们是没有意义的shell脚本,但vim将很难要知道(这是一个编辑!)。所以,它会改变线条的颜色,因为它们不再是这里的文档的一部分。

cat确实没有必要。该行可写成:

python > target.txt <<EOS 
+0

非常感谢。我需要检查另一点 – stacksmith