Rails:如何使用Bash脚本运行“rake”命令?

时间:2011-03-25 08:10:54

标签: ruby-on-rails ruby-on-rails-3 bash

我使用以下内容创建了 reset_db.sh (包含chmod +x):

#!/bin/bash
echo "*** Deleting the database ***"
rake db:drop --trace
echo "*** Creating the database ***"
rake db:create --trace
echo "*** Migrating the database ***"
rake db:migrate --trace
echo "*** Seeding the database ***"
rake db:seed --trace
echo "*** Done! ***"

然而,当我跑步时:

bash reset_db.sh

我明白了:

*** Deleting the database ***
*** Creating the database ***
*** Migrating the database ***
*** Seeding the database ***
*** Done! ***

rake命令未执行。

任何想法为什么?

加分问题:

我应该怎么做才能运行reset_db.sh而不是bash reset_db.sh

2 个答案:

答案 0 :(得分:4)

在bash脚本的顶部添加set -x以获得更详细的输出。

#!/bin/bash

set -x

echo "*** Deleting the database ***"
rake db:drop --trace
echo "*** Creating the database ***"
rake db:create --trace
echo "*** Migrating the database ***"
rake db:migrate --trace
echo "*** Seeding the database ***"
rake db:seed --trace
echo "*** Done! ***"

这能为您提供更多信息吗?

答案 1 :(得分:2)

运行您需要输入的命令:

./reset_db.sh

关于rake命令,你是否在应该启动rake的文件夹中?