The example I provided will put the shell script output in the Gambas variable called "whooutput". It's a string, so you'd then have to extract the number from the string to determine how many logged-in users there are (probably with val(whooutput)).
I've been doing Unix shellscripts for about 24 years at this point, so I'm afraid I wouldn't know where a beginner should look. There isn't much to learn regarding using them in Gambas specifically; what I told you above, plus a trip to gambasdoc.org to look for the SHELL and EXEC keywords, should be enough to get you on your way.
http://www.freeos.com/guides/lsst/ claims to be a shell script tutorial for beginners. What I saw of it seems okay. O'Reilly has books about it too, if you prefer paper. But basically, any set of commands you type in a shell can be put into a shell script. The following one-line shell script I wrote years ago will tell you what the resolution and codec of one or more video files are, by looping through them, running mplayer with some parameters on each one, filtering the output to include only the relevant lines, and prepending the filename to the resulting output:
#!/bin/bash
for f in "$@"; do echo $f: `mplayer -frames 90 -ao null -vo null -nofs -noloop $f 2>&1 | grep VIDEO`; done
The for loop (with a variable), backquotes and pipe used in that example are probably the three most common techniques you need to do what you want to do in a shell script. The "#!/bin/bash" comment goes at the beginning of the file to tell Linux that it's a bash script.
Edit: depending on how new you are to Linux/Unix, you may also need to know that "$@" in quotes gives you a list of the arguments provided to the script, "2>&1" includes error output in the regular output of a program (normally they're split), and "grep" filters output to include only lines matching its first argument.