好像是错误的shell脚本:cat

时间:2013-02-07 02:37:26

标签: linux shell cat

使用此start.sh脚本时遇到问题。 当我输入 ./start.sh,它不起作用。 我的意思是,它没有任何错误,但它什么也没做。

当我使用VIM打开此文件时(我真的想上传图片,但我不能因为我几天前注册了这个网站) 来自import sys,math,random的行 到print '\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

1 个答案:

答案 0 :(得分:1)

脚本没有任何明显的错误。标记为红色的部分是“此处文档”,它从包含<<EOS的行之后的行到仅包含EOS的行。这里的文档作为Python的标准输入提供,它将其输出写入文件target.txt。该脚本的其余部分在rnn-learn文件上运行target.txt命令,由配置文件config.txt引导(我猜)。

当你将#放在包含cat命令的行前面时,它会成为注释,因此以下几行是'just shell script' - 它们作为shell脚本没有意义,但vim很难知道(这是一个编辑!)。因此,它会改变线条的颜色,因为它们不再是此处文档的一部分。

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

python > target.txt <<EOS