I am currently following a tutorial about shell scripting located here:http://www.cs.columbia.edu/~sauce/tutorial/ashell.html and I believe my script matches that one exactly. However, when I try to run the example, my output does not match. Since I don't want to be vague and simply ask why doesn't it work?, I will focus on the part I don't understand: why is there a : after the testlogin: command? I have read many forums that discuss the meaning of  :  (with spaces on either side) and also a leading :, but none mention the use of the lagging colon. What is the meaning in this context? And if this is a typo, can anyone help me find another typo in the example that might be making it not run correctly?Any help would be greatly appreciated!the code (copied exactly from the site I linked above) is below:#testloginuseron(){if ( who | grep $1 > /dev/null)then echo $1 is logged inelse echo $1 is not logged infi }if test $# != 1then echo testlogin: usernameelse useronfiand the output of paul@paul-LC22UP:~$ .testlogin paulUsage: grep [OPTION]... PATTERN [FILE]...Try 'grep --help' for more information.is no logged in
What is the meaning of a trailing : (colon) in *nix?
shell script
testlogin isn't a command here, but an argument to echo. The full command is: echo testlogin: usernameecho just spits out the text you give it to STDOUT. So the colon has no special meaning, it is part of the verbatim output of echo. This is the output if you call the script with the wrong number of arguments:$ ./testlogintestlogin: username$ ./testlogin fred bill adamtestlogin: usernameThis is a strange output, but not necessarily a typo. I would usually expect something more along the lines of:$ ./testloginUsage: testlogin usernameThe reason the whole script doesn't work is because the author has made a subtle mistake in calling the useron function, and presumably hasn't tested their script before posting it (or they would have noticed the same error you did). $1 in the useron function is the first argument to that function, not to the whole script; but since useron wasn't called with any arguments, that is the empty string and so it ends up running the command:$ who | grepwhich will give greps usage info, and then always trigger the else branch of the condition. You can fix this by passing the first argument to the script into useron like this:else useron $1