I like my node.js
so much, that I want to use it is my bash
start up script ~/.bashrc
, but I do not know how to export variable.
Currently I have to use this approach:
export PS1=`node ~/PS1.js`
export PS2=`node ~/PS2.js`
export PATH=`node ~/PATH.js`
instead I want .bashrc
look have
#!/usr/local/bin/node
//do something, define functions
export_var('PS1', PS1())
export_var('PS2', PS2())
export_var('PATH', generatePATH())
process.env.PATH = something
does not export, only sets for the currently executing process, which is node itself.
One possible way is to use JS to print out the export statements, then in shell to use eval to evaluate it in the current shell.
e.g. test.js
#!/usr/bin/env node
console.log('export A=40; export B=10');
In the shell:
eval `./test.js`
echo $A
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