错误:在bash中找不到ps命令

错误:在bash中找不到ps命令,bash,shell,Bash,Shell,我在执行这个bash脚本时出错,该脚本会打印“hello”,直到后台进程继续执行 ps command not found 我以前做过几次,但不确定这次为什么会出错 ./a.sh & while ps -p $! > /dev/null; do echo hello done 要调试这个问题,我建议如下 nohup ./a.sh & p1=$! while ps -p $p1 do echo hello sleep 1 do

我在执行这个bash脚本时出错,该脚本会打印“hello”,直到后台进程继续执行

ps command not found 
我以前做过几次,但不确定这次为什么会出错

./a.sh &
while ps -p $! > /dev/null; do
       echo hello
done

要调试这个问题,我建议如下

 nohup ./a.sh &
 p1=$!

 while ps -p $p1 
 do
    echo hello
    sleep 1
 done

这并不能解决明显的
PATH
问题,但有一种比反复调用
ps
更简单的方法

# Start your script in the background, remembering its process ID
./a.sh & A_PID=$!

# Start another background job that echos hello (once per second, to
# avoid a flood of hellos). Remember its process ID as well
( while : ; do echo hello; sleep 1 done ) & LOOP_PID=$!

# Now wait for a.sh to finish...
wait $A_PID

# ... and kill the hello job
kill $LOOP_PID

你把小路弄乱了吗?你还有/bin/ps吗?我已经验证过了,路径有这个位置到pso什么是完整输出,它运行一次然后停止吗?或者它是否立即抛出命令未找到错误?它抛出此错误。/test.sh:line xx:ps:command未找到,并继续执行a.sh“PATH has this location to ps”很显然没有。要么你删除了ps,要么把你的路径弄乱了
echo$PATH
ls/usr/bin/ps
将告诉您是哪个。