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会话.

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

相关文章

用的openwrt路由器,家里宽带申请了动态公网ip,为了方便把2...
#!/bin/bashcommand1&command2&wait从Shell脚本并行...
1.先查出MAMP下面集成的PHP版本cd/Applications/MAMP/bin/ph...
1、先输入locale-a,查看一下现在已安装的语言2、若不存在如...
BashPerlTclsyntaxdiff1.进制数表示Languagebinaryoctalhexa...
正常安装了k8s后,使用kubect工具后接的命令不能直接tab补全...