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

3

我想在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个回答

2
你可以使用$(命令扩展)"$变量扩展"来实现这一点:
# 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
你可以用反引号将第一个命令包裹起来以执行它,然后使用$在下一个命令中引用它:
# 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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接