Artificial intelligent assistant

Why does finger not have a non-zero return value? I often use the return/status value of a command in scripts. I'm curious why the finger command doesn't have a return value. E.g., $ finger kevin Login: klang Name: Kevin Kang etc... Shell: /bin/bash No mail. No Plan. $ echo $? 0 $ finger blabla finger: blabla: no such user. $ echo $? 0 Tested under Ubuntu and RH. I guess I could do some string processing and look for the "no such user" response, but that seems cumbersome. The man page doesn't list _any_ return values. * * * Yes yes, it has a return value of zero, but that's not helpful if that's the _only_ value it has - I didn't realize I had to actually spell that out.

`finger` doesn't consider a not found situation to be worth a non zero return code.

There are however real error cases like:


$ finger -x
finger: invalid option -- 'x'
usage: finger [-lmps] [login ...]
$ echo $?
1


Changing `finger` behavior would be trivial by modifying its source code but this was not done probably not to break scripts that expect finger never to fail.

I'm afraid you have to keep on with post-processing finger output to achieve your goal if you need to stick with `finger`..

Alternatively, you might use `getent` which supplies a useful return value:


$ getent passwd root
root:x:0:0:root:/root:/bin/bash
$ echo $?
0
$ getent passwd foo
$ echo $?
2

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 2c7c363f620d794b6bf738117f8e21cc