我正在尝试在运行时将输入提供给Shell脚本。我已经做到了,但是该值需要由JS文件使用。请帮我怎么做
TIME = $ {1:-80}
这就是我在运行bash脚本时要求用户提供输入的方式
Java脚本文件需要从bash文件中获取值
答案 0 :(得分:0)
只需从shell脚本中调用CLI,然后将$TIME
作为参数传递即可。
答案 1 :(得分:0)
您可以使用process.argv[2]
在js文件中使用传递的参数。这是工作示例
#!/bin/bash
time="${1}"
echo "Argument is $time"
#pass the the argument to JS file
node test.js $time
#or you can pass without assigning to variable
node test.js $1
您应该从bash脚本中调用nodejs脚本以传递参数。
test.js
const args = process.argv;
console.log(args);
// or you can try
var program_name = process.argv[0]; //value will be "node"
var script_path = process.argv[1]; //value will be "test.js"
var time_value = process.argv[2]; //value will be "time that is passed from bash file"
console.log("time in JS file",time_value);