I am working on an assignment that requires me to accept user input to search for current users on the server and if the user input is online, I need to output the users name. If the user is not logged in I need to respond accordingly. I have been working on this code for days and can't seem to figure it out. I can search for the user but when it comes to comparing my user input variable string with the variable string holding the users name who is logged in I keep getting an error that says too many arguments. Please see my code below:
#!/bin/bash
read -p "Please enter the user name you would like to search: " userName
name=$(who | grep "${userName}" | awk '{print $1}');
if [ [ $name == *"$userName"* ] ];
then
echo $name
else
printf "That user is not logged in.\n";
fi