所以我正在编写一个脚本,该脚本应该使用 (bash) -x 检查包是否具有现有路径并相应地回显消息。如何在函数中正确实现我的条件?
在这里我真的没有我有限的选择。
#!/bin/bash
exists() {
if [[ -x $(type -P "$1" 1>hra 2>/dev/null) ]]; then
return 0
else
return 1
fi
}
read key | exists
if [ "$?" -eq 0 ] ; then
echo $(cat hra) | echo $(awk -F "/" '{print $NF}' ) "is installed"
else
echo $(cat hra) " needs to be installed"
fi
如果路径存在且可执行,我希望行 [[ -x $(type -P "$1"1>hra 2>/dev/null) ]]
为真,但是该函数始终返回 1。
最佳答案
你的代码中有很多问题!以下内容还不够吗?
#!/bin/bash
read -r key
if type -aP "$key"; then
echo "$key is installed"
else
echo "$key needs to be installed"
fi
关于linux - bash 条件表达式 -x 可以看作是 if 条件吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54570535/