---
title: "用 shell script 检查命令是否存在"
description: "用 shell script 检查命令是否存在"
canonical: https://oozou.com/til/check-if-command-exists-with-shell-script-52
locale: zh-Hans
date: 2020-10-13
topic: shell
---

# 用 shell script 检查命令是否存在

> 用 shell script 检查命令是否存在

Published: 2020-10-13 · Topic: [shell](https://oozou.com/zh-Hans/til-topics/shell) ([markdown](https://oozou.com/zh-Hans/til-topics/shell.md))

```bash
if ! type gem > /dev/null; then
  echo 'gem command not found.'
fi
```

---

Contact OOZOU: hello@oozou.com · +66 2544 0000 · https://oozou.com/zh-Hans/contact

More for AI agents: https://oozou.com/llms.txt · every page has a markdown twin at its URL plus ".md"
