我已经为这个问题苦苦挣扎了几个小时,并尝试了我在讨论板上能找到的一切。我无法切换到bash
,这是bin/sh
问题出在 while 循环上,while [ $currentID -gt 0 ]
.错误" 21: [: 2893: unexpected operator
#!/bin/sh
Menu_Option=0
echo "WELCOME"
echo "--------------------------------------------------------------"
while [ $Menu_Option -ne 4 ]
do
echo "select a menu option"
echo "1- ancestry history"
echo "2- who is online"
echo "3- what process any user is running"
echo "4- exit"
read Menu_Option
case $Menu_Option in
1)
echo "THE ANCESTRY TREE FOR CURRENT PROCESS IS...."
echo " "
ps -ef > file1
currentID=$(awk '{if ($3 == '$PPID') print $2}' file1)
while [ $currentID -gt 0 ]
do
Process_Name=$(awk '{if ($2 == $currentID) print $8 " " $9}' file1)
我希望
以下是您需要的:
#!/bin/sh
Menu_Option=0
echo "WELCOME"
echo "--------------------------------------------------------------"
while [ $Menu_Option -ne 4 ]
do
echo "select a menu option"
echo "1- ancestry history"
echo "2- who is online"
echo "3- what process any user is running"
echo "4- exit"
read -r Menu_Option
case $Menu_Option in
1)
echo "THE ANCESTRY TREE FOR CURRENT PROCESS IS...."
echo " "
ps -ef > file1
currentID=$(awk '{if ($3 == '$PPID') print $2}' file1)
while [ "$currentID" -gt 0 ]
do
Process_Name=$(awk '{if ($2 == '"$currentID"') print $8 " " $9}' file1)
echo "$Process_Name"
currentID=$(awk '{if ($3 == '"$currentID"') print $2}' file1)
if [ "$currentID" = "" ]
then
currentID=-1;
fi
done
echo ""
esac
done