【发布时间】:2019-03-14 22:14:54
【问题描述】:
我有一个脚本sh startAWS.sh。
最重要的是,我检查了这个:
if [[ `ps -acx|grep postgres|wc -l` < 1 ]]; then
echo "You need to start your Postgres service to run this script."
ps -acx|grep postgres|wc -l
exit 0
fi
当我跑步时,我得到了
⚡️ laravel sh startAWS.sh
You need to start your Postgres service to run this script.
6
嗯...什么... ??????????♂️
我的 Postgres 正在运行,不应执行该 echo。
显示6,且6不小于1,该代码不应该被执行。
有人知道为什么我的 echo 会打印出来吗?
【问题讨论】:
-
if [ $(pgrep postgres | wc -l) -lt 1 ]; then怎么样 -
正如@Mostafa 所说,您可能应该使用
if [[ $(ps -acx|grep postgres|wc -l) -lt 1 ]]; then...$(...)可以嵌套,不像反引号。
标签: linux bash shell ubuntu unix