使用“包”制作.pkg文件时编写shell脚本

时间:2018-09-20 01:07:41

标签: macos shell pkg-file

我真的需要您的帮助:    问题是:我试图将我的应用程序构建到.pkg文件中,同时我想将node.js集成到我的.pkg安装文件中,如果操作系统没有nodejs,它将被安装。    当我尝试编写脚本来判断用户是否已经安装了该节点时,我被“外部脚本的返回值”所困扰。我在最后用“ echo”,“ return”,“ exit”尝试了我的脚本,但仍然无法正常工作。enter image description here

这是我尝试插入脚本时“ Packages”的屏幕截图。

这是我写的脚本。#!/ bin / bash

OUTPUT="$(node -v)"
    echo ${OUTPUT}
if [[ $OUTPUT = "" ]];
then
    echo "1"
    return 1
    #no node
else
    echo "0"
    return 0
    #node found
fi

` 请帮助我

1 个答案:

答案 0 :(得分:0)

此脚本将运行“ node -v”命令并将输出(stderr和stdout)发送到/ dev / null;没有显示给用户。 if条件检查命令是否成功运行,并根据结果将退出状态设置为0或1。

#/bin/bash

main() {
    node -v >/dev/null 2>&1
    if [[ $? -eq 0 ]]; then
        return 0
    else
        return 1
    fi
}

main