微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

linux-如何在bash -c命令中插入变量

这个问题已经在这里有了答案:            >            Difference between single and double quotes in Bash                                    6个
>            Defining a variable with or without export                                    14个
我可以执行以下操作:

$FOO="text"
$echo $FOO
$text

但是如何将其包装在bash -c构造中?我尝试了这个但是失败了:

$FOO="text"
$bash -c 'echo $FOO'
$# return nothing

我之所以这样问,是因为我需要执行另一个需要包装在bash -c中的第三方代码

解决方法:

尝试

$export FOO="text"
$bash -c 'echo $FOO'

export command is used to export a variable or function to the
environment of all the child processes running in the current shell.

Here’s the source

“ bash”命令启动一个子进程,其父进程是您当前的bash会话.

要在父进程中定义变量并在子进程中使用它,必须将其导出.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐