找到确切的单词exist

问题描述 投票:0回答:1

我刚刚开始使用 Dockerutil 以及如何编写执行以下操作的脚本。

检查 Dock 上是否存在该项目。如果它不存在,请添加它。如果它没有任何作用。

要检查项目是否存在,您可以使用以下命令

~ % dockutil --find Keynote

结果将回显以下内容

Keynote was not found in Keynote was not found in /Users/$UserName/Library/Preferences/com.apple.dock.plist

所以我编写了以下脚本来捕获输入

 app='Keynote'
echo "${app}"


Test=$(dockutil --find "${app}" | tr ' ' '\n'| grep "not")

  if [[ ${Test} == "not" ]]; then

  echo " its not there "

else

  echo "its there"

fi

问题是 Keynote 的名称中有“not”这个词,这总是会给我一个误报。 有没有办法从结果中查找“未找到”甚至“未找到”。或者甚至可能是一起执行 if 语句的另一种方式。

bash macos zsh shebang
1个回答
0
投票

dockutil
如果没有找到该项目,则以 1 退出,那么你可以这样做

app='Keynote'
echo "${app}"


if ! dockutil --find "${app}"; then
    echo " its not there "
fi
© www.soinside.com 2019 - 2024. All rights reserved.