ps -ef 命令未找到 shell 脚本
ps -ef COMMAND NOT FOUND shell script
当我运行命令
ps -ef | grep -i this | head -n 1 | awk '{print }'
在我的终端中,它为我提供了正确的输出,为我提供了 'this' 服务所需的 PID。
但是当我尝试将它放在 shell 脚本变量中时
PID=ps -ef | grep stress | head -n 1 | awk '{print }'
并尝试 运行 脚本,输出是 line 9: -ef: command not found
求助!
为了将 ps 命令的输出读入变量 PID,您需要使用 $() 等:
PID=$(ps -ef | grep stress | head -n 1 | awk '{print }')
当我运行命令
ps -ef | grep -i this | head -n 1 | awk '{print }'
在我的终端中,它为我提供了正确的输出,为我提供了 'this' 服务所需的 PID。
但是当我尝试将它放在 shell 脚本变量中时
PID=ps -ef | grep stress | head -n 1 | awk '{print }'
并尝试 运行 脚本,输出是 line 9: -ef: command not found
求助!
为了将 ps 命令的输出读入变量 PID,您需要使用 $() 等:
PID=$(ps -ef | grep stress | head -n 1 | awk '{print }')