bash - IF 语句总是计算为真
问题描述
我有以下片段,其中函数test
echoes false
。if
我在带有 shell 替换的语句中使用回显值:
#!/usr/bin/env bash
test () {
echo "false"
}
if [[ "$(test)" -eq "true" ]]
then
echo hello world
fi
我希望上面不打印hello world
,因为我认为这最终会说[[ "false" -eq "true" ]]
。
但是,当我运行脚本时,它会回显hello world
。
解决方案
尝试这个
#!/usr/bin/env bash
test () {
echo "false"
}
if [[ "$(test)" = "true" ]]
then
echo hello world
fi
推荐阅读
- angular - 在 primeNG 焦点上未触发 completeMethod 事件
- r - SASxport 到 R:读取 XPT SAS 文件时出错
- java - 如何提高算法的运行时间?
- git - 使用过滤器干净地列出所有远程分支
- asp.net-core - 如何在 ASP.NET Core 应用程序中使用领域集合通知?
- java - RecyclerView 列表项不显示也不播放
- python - 我的连接超时的原因是什么?
- python - 在 Google Colab 中保存失败
- javascript - 如何为 React to-do 应用添加完整的功能?
- amp-html - AMP:数据加载回调函数的 amp-state