这是一个非常奇怪的问题,关于使用 pgrep 搜索哪些 shell 进程正在运行与当前进程相同的脚本。
\n这是名为test.sh的测试脚本
\n#!/bin/bash\n\nfull_res=`pgrep -a -l -f \'test\\.sh\'`\n\nres=$(pgrep -a -l -f \'test\\.sh\' | cat)\n\necho "short result is $full_res"\n\necho "weird result is $res"\nRun Code Online (Sandbox Code Playgroud)\n输出为
\nsh test.sh &\n[1] 19992\n\xe2\x9e\x9c logs short result is 19992 sh test.sh\nweird result is 19992 sh test.sh\n19996 sh test.sh\n\n[1] + 19992 done sh test.sh\nRun Code Online (Sandbox Code Playgroud)\n我不知道这些声音从何19996 sh test.sh而来,尤其是在使用管道猫时。我相信这可能是 pgrep 实现的一个错误。
期待合理的解释
\n谢谢,
\n巴林
\n