Linux中的命令替换-在bashrc中设置变量(用户名和密码)
我对linux非常陌生。我想做命令替换。我想在bashrc中定义一个变量,并将其设置为等于linux命令的返回值。它的语法是什么 这正是我想要做的。我在heroku上部署了Rails 4应用程序,我正在heroku上使用Sendgrid发送电子邮件。现在,当我在控制台(本地文件夹my_app_文件夹)中键入Linux中的命令替换-在bashrc中设置变量(用户名和密码),linux,bash,heroku,sendgrid,Linux,Bash,Heroku,Sendgrid,我对linux非常陌生。我想做命令替换。我想在bashrc中定义一个变量,并将其设置为等于linux命令的返回值。它的语法是什么 这正是我想要做的。我在heroku上部署了Rails 4应用程序,我正在heroku上使用Sendgrid发送电子邮件。现在,当我在控制台(本地文件夹my_app_文件夹)中键入heroku config:get SENDGRID_USERNAME(或heroku config:get SENDGRID_PASSWORD)时,它会返回我的SENDGRID用户名(或密码
heroku config:get SENDGRID_USERNAME
(或heroku config:get SENDGRID_PASSWORD
)时,它会返回我的SENDGRID用户名(或密码)。我想在baschrc中定义一个变量,SENDGRID\u USERNAME
,并将其设置为等于heroku config:get SENDGRID\u USERNAME
的返回值(而不是复制粘贴实际值)。我怎么做?如下所示:
export SENDGRID_USERNAME=my_app_folder/heroku config:get SENDGRID_USERNAME
非常感谢。这就是你要找的吗
SENDGRID_USERNAME=$( path/to/heroku config:get SENDGRID_USERNAME )
# ^^ ^
在执行时,$(…)
被括号中的命令输出替换。引述:
Command Substitution
Command substitution allows the output of a command to replace the com‐
mand name. There are two forms:
$(command)
or
`command`
Bash performs the expansion by executing command and replacing the com‐
mand substitution with the standard output of the command, with any
trailing newlines deleted.