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

Mis*_*hko 1 bash ruby-on-rails ruby-on-rails-3

我使用以下内容创建了reset_db.sh (with 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! ***"
Run Code Online (Sandbox Code Playgroud)

但是,当我运行时:

bash reset_db.sh
Run Code Online (Sandbox Code Playgroud)

我懂了:

*** Deleting the database ***
*** Creating the database ***
*** Migrating the database ***
*** Seeding the database ***
*** Done! ***
Run Code Online (Sandbox Code Playgroud)

rake没有执行命令。

任何想法为什么?

奖金问题:

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

leb*_*eze 5

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

#!/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! ***"
Run Code Online (Sandbox Code Playgroud)

这是否为您提供了更多信息?