linux - 如何检查 bash 脚本中的依赖关系

标签 linux bash

我想查看系统是否安装了nodejs。我收到此错误:

Error : command not found.

我该如何解决?

#!/bin/bash

if [ nodejs -v ]; then
echo "nodejs found"
else
echo "nodejs not found"
fi

最佳答案

您可以使用 command bash builtin :

if command -v nodejs >/dev/null 2>&1 ; then
    echo "nodejs found"
    echo "version: $(nodejs -v)"
else
    echo "nodejs not found"
fi

关于linux - 如何检查 bash 脚本中的依赖关系,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33297857/

相关文章:

arrays - 在 bash robuSTLy 中传递部分命令

c++ - C/C++裸机编译和针对特定操作系统(Linux)的编译有什么区别?

linux - i3blocks (i3wm) - 使用 sudo 命令

linux - 如何在 linux 中组合 ls -v 和转换命令

linux - X-FRAME 允许来自 https ://www. example.com

c++ - 在 X11 下如何判断你的光标是否指向你的桌面

linux - DC/OS ssh 连接在端口 22 上被拒绝 - 预检

bash - 在 shell 脚本的 while 循环中运行 expect 命令

bash - Unix 如何根据特定匹配对整行进行排序

bash - 为什么Bash读取命令没有输入就返回?