Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
114
rated 0 times [  117] [ 3]  / answers: 1 / hits: 17639  / 7 Years ago, sun, april 2, 2017, 12:00:00

Let's say I have a bash script that calls a node script. I've tried to do it like this:



b.sh file:



#!/bin/bash
v=$(node app.js)
echo $v


app.js file:



#!/usr/bin/env node
function f() {
return test;
}
return f();


How do I access the value returned by the node script (test) from my bash script ?


More From » node.js

 Answers
7

@Daniel Lizik gave an good answer (now deleted) for the part: how to output the value, e.g. using his answer:



#!/usr/bin/env node
function f() {
return test;
}
console.log(f())


And for the part how to capture the value in bash, do exactly as in your question:



#!/bin/bash
val=$(node app.js)
echo node returned: $val


the above prints:



node returned: test

[#58303] Thursday, March 30, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
leslijessalyng

Total Points: 650
Total Questions: 85
Total Answers: 109

Location: Croatia
Member since Mon, Sep 6, 2021
3 Years ago
leslijessalyng questions
Fri, Feb 21, 20, 00:00, 4 Years ago
Tue, Jul 30, 19, 00:00, 5 Years ago
Fri, Jul 5, 19, 00:00, 5 Years ago
Wed, Mar 13, 19, 00:00, 5 Years ago
;