我有一个非常基本的脚本,它不断吐槽找不到命令。我看遍了这个网站,找不到适合我的答案。抨击的路径是正确的。我用od检查了脚本。Ive run dos2unix.这些对我都没有帮助。
脚本:
#!/bin/bash
HYBRISPROC=`ps -eo pid,command | grep [h]ybris | grep -v grep | awk '{print $1}'`
echo "Looking for Hybris..."
echo $HYBRISPROC
结果:
./HybrisStopStart.sh: line 5: ps: command not found
./HybrisStopStart.sh: line 5: grep: command not found
./HybrisStopStart.sh: line 5: awk: command not found
./HybrisStopStart.sh: line 5: grep: command not found
Looking for Hybris...
有什么想法吗?如果我只运行命令本身,它可以正常工作。我也尝试将其作为 sudo 并且结果相同。
蒂亚
怎么样
?
#!/bin/bash
HYBRISPROC=`ps -eo pid,command | grep [h]ybris | grep -v grep | awk '{print $1}'`
echo "Looking for Hybris..."
echo "$HYBRISPROC"
(或)
#!/bin/bash
HYBRISPROC="ps -eo pid,command | grep [h]ybris | grep -v grep | awk '{print $1}'"
echo "Looking for Hybris..."
bash -c "$HYBRISPROC"
(或)
#!/bin/bash
HYBRISPROC="ps -eo pid,command | grep [h]ybris | grep -v grep | awk '{print $1}'"
echo "Looking for Hybris..."
eval "$HYBRISPROC"
总计:
您可以看到差异:
#!/bin/bash
LS=`ls -l`
echo $LS #nasty way
echo
echo "$LS" #good way
尝试添加
PATH="$PATH:/usr/bin:/bin"
在代码之前。看起来 bin 目录不在您的路径上。因此找不到命令。