Let's say there is a variable key1
and its value is 123
key1=123
so when I run the command in linux environment echo $key1
, I get output as 123
.
Now I have the following gulp task.
const child_process = require('child_process');
....
gulp.task('printKeyValue', function() {
var value1 = child_process.execSync('echo $key1');
console.log(value1.toString().trim());
});
Here, I'm trying to access value of linux variable from nodejs by using Child Process
But when I run the following gulp task, I don't get the desired output.
npm run gulp -- printKeyValue
Instead I get output as $key1
and not 123
.
See below screenshot
Other commands like ls
& pwd
in gulp task gives the desired output.
Can some one please help on this or suggest an alternate way?