我正在编写一个脚本,该脚本将首先检查当前是否安装了 Node,如果没有,它将安装最新版本的 Node。如果安装了,那么它将继续执行另一个功能来更新它。
我当前的脚本:
#!/bin/bash
function isNodeInstalled() {
clear
echo "Checking if Node is installed ..."
if command --version node &>/dev/null; then
echo "Installing Node ..."
curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -
sudo apt-get install nodejs -y
echo "Node has been installed."
sleep 5
updateNode
else
echo "Node has already been installed."
sleep 5
updateNode
fi
}
答案1
if which node > /dev/null
then
echo "node is installed, skipping..."
else
# add deb.nodesource repo commands
# install node
fi
答案2
-P
(仅支持 bash)使用type
命令。
#!/bin/bash
if type node > /dev/null 2>&1 && which node > /dev/null 2>&1 ;then
node -v
echo "node is installed, skipping..."
else
echo "install node"
fi