I am trying to perform a variable swap where the user enters 2 different numbers and a check is performed to make sure that the second number "end" is bigger then the first number "start". If the starting number is bigger then the end number it will perform a swap so that the later calculations will work.
The error that I am getting is: ./Boot.sh: line 94: [: -ne: unary operator expected
if [ $end -gt $start ]
then
start=$swapper
end=$start
swapper=$end
fi
This is the full code as I seem to have made a few mistakes by the comments, I have just tried double brackets and am still having the same error.
{
counter=0
while :
do
if [ $counter -gt '0' ]
then
printf "\nWould you like to continue terminating processes?\n"
echo "Type 1 to contiue or 0 to exit"
read endProgram
if [ $endProgram -ne '1' ]
then
break
fi
fi
echo "Welcome to Max process killer"
while :
do
echo "Enter the first number of the process range"
read start
echo "Enter the last number of the process range"
read end
if [ $start -le '3' -o $end -le '3' ]
then
echo "Your first and last pid IDs must be geater then 3"
read -n 1
break
if [[ $end -gt $start ]]
then
start=$swapper
end=$start
swapper=$end
fi
fi
printf "\nAre you sure you would like to terminate these processes?\n"
echo "Enter 1 to confirm or 0 to cancel"
read confirm
if [ $read -ne '1' ]
then
break
fi
while [ $start -le $end ]
do
kill -9 "$start"
echo "Process ID:"$start "has been terminated"
start=$(( $start + 1 ))
done
break
done
counter=$(($counter + 1))
done
}
if?-ne.