gpt4 book ai didi

linux - shell 脚本 : pacmd: no command found

转载 作者:太空宇宙 更新时间:2023-11-04 11:01:21 24 4
gpt4 key购买 nike

我正在尝试编写一个简单的 shell 脚本来检测 clementine 是否正在运行。如果是,它将关闭省电功能。我在终端中尝试了 pacmd 命令,它运行良好,但在脚本中却没有。在第一个错误“找不到 pacmd 没有命令”之后,我输入了完整路径,然后它说“./noSleep.sh:第 5 行:[/usr/bin/pacmd:没有这样的文件或目录”。所以我不知道为什么找不到它。有帮助吗?

我不想在 clementine 不播放音乐时关闭省电功能。所以我不想用 ps x | grep 克莱门汀。

#!/bin/bash

while true
do
if [/usr/bin/pacmd list-sink-inputs | grep Clementine]
then
xset -dpms; xset s off
else
xset +dpms; xset s on
fi

sleep 2m
done

脚本更新:

#!/bin/bash

while true
do
if [ `echo pacmd list-sink-inputs | grep "Clementine" | wc -l` ]
then
xset -dpms; xset s off
echo off
else
xset +dpms; xset s on
echo on
fi

sleep 30s
done

出于某种原因,它每次都返回 true。我在测试 pacmd 语句时测试了 Clementine 不玩和玩。字符串 Clementine 在播放时显示,不播放时不显示,所以我不确定为什么它不起作用。

最佳答案

总是在 [ 之后和 ] 之前在 if 语句中使用一个空格,正如上面在 cyrus 的评论中提到的那样,你也没有在你的 if 语句中测试任何东西

grep -c "Clementine" 命令检查 "Clementine" 在命令输出中出现的次数 /usr/bin/pacmd list-sink -inputs 所以如果它大于 0 它可能是打开的。

while true
do
if [ "$(/usr/bin/pacmd list-sink-inputs|grep -c "Clementine")" -gt 0 ]
then
xset -dpms; xset s off
else
xset +dpms; xset s on
fi

sleep 2m
done

关于linux - shell 脚本 : pacmd: no command found,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26942779/

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