&quot“ grep -v”怪异的行为
我正在尝试确保我的脚本一次只能运行一次,但是我会遇到奇怪的行为。
我的代码:
echo "Current Pid: $$"
# Output "Current Pid: 5387"
echo "Process Count: $(pgrep -c -f "$0")"
# Output: Process Count: 2
if [ "$(pgrep -c -f "$0")" -gt 1 ]
then
echo All Pids
pgrep -f "$0"
# Output "4978, 5387"
echo Pids Current
echo "$(pgrep -f "$0" |& grep -F $$)"
# Output "5387"
echo Pids Inverted
echo "$(pgrep -f "$0" |& grep -Fv $$)"
# Output "4978, 5394"
# processPidsToKill="$(pgrep -f "$0" |& grep -Fv $$)"
# for processPid in $processPidsToKill; do
# echo "Killing `basename "$0"` $processPid"
# kill "$processPid"
# done
fi
有人可以告诉我我在做什么错吗? 新的PID来自我使用“ GREP -V”时?
I'm trying to make sure my script only runs once at a time, but im running into weird behavior with inverting grep.
My Code:
echo "Current Pid: $"
# Output "Current Pid: 5387"
echo "Process Count: $(pgrep -c -f "$0")"
# Output: Process Count: 2
if [ "$(pgrep -c -f "$0")" -gt 1 ]
then
echo All Pids
pgrep -f "$0"
# Output "4978, 5387"
echo Pids Current
echo "$(pgrep -f "$0" |& grep -F $)"
# Output "5387"
echo Pids Inverted
echo "$(pgrep -f "$0" |& grep -Fv $)"
# Output "4978, 5394"
# processPidsToKill="$(pgrep -f "$0" |& grep -Fv $)"
# for processPid in $processPidsToKill; do
# echo "Killing `basename "$0"` $processPid"
# kill "$processPid"
# done
fi
Can someone tell me what im doing wrong?
Where does the new Pid come from when im using "grep -v"?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论