You all would have the right to call me Bozo its ok.
I am really not bad at bash, but the simplest things just take my wickets sometimes. This is a part of a daemon for an @reboot script I am forced to write since cron decides not to have @reboot available for useraccounts, missing probably the most important user space functionality. Dont know whats up with the cronfolks. I have the really difficult issues in the script sorted out, but stumble over the following triviality.
There are still somethings I dont understand about command substituion and also things related to simple evaluation of variables from commands.
I want to settle this triviality once and for all.
Say for example we have root mo and curly as users logged in
username="$(whoami)" #Lets say we are mo
loggedin=$(users |grep -i $username)
Now here is where I get confused.
$] $ loggedin
Which is exactly what I want,
$] “$ loggedin”
root mo curly
Looking at how loggedin is defined this should JUST BE moe
This is not what I want as I want a text string to use in conditions
[ “$username” = “$loggedin” ] should equate mo with mo and be true.
At the moment it equates as false because of al the root and curly eroneously in “$loggedin”
So question is
How do I force a variable such as loggedin to only contain user moas the output of $(users |grep -i $username)
Meaning it should only give mo. when I execute “loggedin”