gpt4 book ai didi

linux - 检查变量是否有值或为空?

转载 作者:太空宇宙 更新时间:2023-11-04 04:47:27 25 4
gpt4 key购买 nike

如果条件无法正常工作,请参见以下内容。请指教。我有 java process id ,但在下面工作“没有进程处于事件状态”。为什么 [ -z $PIDS ] 不起作用?

PIDS= pgrep -f java

if [ -z "$PIDS" ]
then
echo "No process alive...."
exit 1
else
echo "An instace is running in background."
fi

最佳答案

如果您希望 PIDS 包含运行该命令的输出,您需要告诉 shell:

PIDS="$(pgrep -f java)"

关于linux - 检查变量是否有值或为空?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25752916/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com