【发布时间】:2021-03-20 18:12:53
【问题描述】:
我设置了一个包含多个值的变量。 (这是我从heroku config --shell 得到的,已编辑)
保存命令输出的命令是
envvars=`heroku config --shell -a heroku-app`
而echo "$envvars"的结果是这样的:
BH_SERVER=000000000000000000
DATABASE_URL='postgres://stringno1:randomstring1@someserver.com:5432/randomstring2'
DISCORD_TOKEN=some.veryveryveryvery.long.token.string
EXM_SERVER=000000000000000001
MUTED_SERVER='000000000000000002, 000000000000000003'
SUPER_USER='000000000000000004, 000000000000000005'
TEST_SERVER=000000000000000006
TZ=Asia/Seoul
现在我想将这些值设置为环境变量。这些不能是永久性的,因为这些只有 python 应用程序需要,稍后将在脚本中执行。我想我可以使用 = 作为分隔键和值的分隔符,但不能 100% 确定这一点。 (我不知道heroku convar 效果如何)
我希望有类似的输出。
echo $BH_SERVER
# 000000000000000000
echo $DATABASE_URL
# postgres://stringno1:randomstring1@someserver.com:5432/randomstring2
# Note that there is no ' in start and end of line
echo $DISCORD_TOKEN
# some.veryveryveryvery.long.token.string
# Note that . is still there.
echo $MUTED_SERVER
# 000000000000000002, 000000000000000003
# Even if there is space in string, it should be treated as one line
# Also, there is no ' in start and end of line
echo $TZ
# Asia/Seoul
# / is not interpreted. I think this is normal.
有一些已经回答的问题,但我没有找到任何符合我条件的答案。
我放了git-bash标签,因为我正在研究Git Bash,但我认为这个问题的解决方案与Bash相同。
【问题讨论】:
-
你试过 eval $envvars 了吗?
-
@Lety 你的意思是
eval $envvar?这只是停止脚本工作。我认为它正在等待用户输入但不确定。
标签: bash environment-variables git-bash