I can do the following:
$ FOO="text"
$ echo $FOO
$ text
But how can I wrap it inside bash -c construct? I tried this but failed:
$ FOO="text"
$ bash -c 'echo $FOO'
$ # return nothing
The reason I ask this because I need to execute another 3rd party code that need to be wrapped inside bash -c
Try
$ 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
The "bash" command starts a child process where its parent is your current bash session.
To define a variable in parent process and use it in child process, you have to export it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With