2016-02-04 93 views
3

我想在bash脚本中运行一些heroku命令。我知道这是完全关闭的,应该采用bash课程,但以下是我想要完成的。如何在bash脚本中运行这两个heroku命令?

# get the database url and assign it to a variable 
URL=heroku config:get DATABASE_URL -a wt2-production 

# insert the variable in another command 
heroku pg:copy URL DATABASE_URL --app my-staging-app 

我该如何在bash脚本中完成此操作?

回答

2

您可以$(command expansion)"$variable_expansion"做到这一点:

# get the database url and assign it to a variable 
URL=$(heroku config:get DATABASE_URL -a wt2-production) 

# insert the variable in another command 
heroku pg:copy "$URL" DATABASE_URL --app my-staging-app 
1

你可以换行的第一个命令,在反引号给exec它&然后使用$来引用它的下一个命令:

# get the database url and assign it to a variable 
URL=`heroku config:get DATABASE_URL -a wt2-production` 

# insert the variable in another command 
heroku pg:copy "$URL" DATABASE_URL --app my-staging-app