如何在bash脚本中运行这两个heroku命令?

时间:2016-02-04 18:30:11

标签: bash heroku

我想在bash脚本中运行一些heroku命令。我知道这完全是关闭的,应该采取bash的方法,但以下是我想要完成的。

# 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 个答案:

答案 0 :(得分: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 :(得分:1)

你可以用反引号包装第一个命令来执行它&然后使用$在下一个命令中引用它:

# 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
相关问题