首页 > 解决方案 > 将值从 typescript 函数导入到 shell 脚本

问题描述

    const printKeyAndValue = (objVal: any) => {
  for (const key of Object.keys(objVal)){
      console.log(key);
      console.log(objVal[key]);   
  }
};
 
const obj = {
    "int": {
        "name": "internal",
        "products": {
            "test": "Internal Test from Actions"
        }
    },
    "tst": {
        "name": "test",
        "products": {
            "action": "Test Actions"
        }
    }

};
 
//printKeyAndValue(obj.tst.products);

const thingtolookup = "Test Actions"
var matchingkey = ""

for (const segment in obj) {

    console.log("Segment: " + segment);
    const segmentobj = obj[segment];
    console.log("Segment: " + segmentobj["name"]);

    const productsobj = segmentobj["products"];
    for(const product in productsobj) {

        console.log("Product: " + product);
        console.log("Value: " + productsobj[product]);

        if(thingtolookup == productsobj[product]) {
            matchingkey = segment + "-" + product;
        }

    }

}

const found = !(matchingkey == "");

console.log("Found? " + found);
console.log("Found: " + matchingkey);

上面的代码是从作业中的 Github 操作中调用的。这需要传递给我正在调用 shell 脚本的另一个工作。我想将上述脚本中的“matchingkey”值传递给 shell 脚本并使用它。

标签: typescriptshellimportreturn-value

解决方案


推荐阅读