Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Determining whether a user name is valid



I share my .zsh{env,rc} across several machines.  On some, but not all, of
these machines, there exist certain files in other users' home directories;
files that, when they exist, I would like to reference from my .zsh{env,rc}.

*If* any of the users in question has an account on a machine, the file is
always found in the same place relative to his home directory.  However,
the home directories themselves are not always in the same places.  Thus I
would like to refer to these files as (e.g.) ~foo/fileX and ~bar/fileY.

Unfortunately, I normally use cshnullglob, which means that a reference to
the named directory ~foo is an error when foo is *not* a known user.  So I
have to find out if foo is a user before I can reference ~foo.  (There is
no equivalent of nullglob for file expansion, though nonomatch applies to
both filename expansion and filename generation.)

So, there are a couple of workarounds I can think of:

	[[ -n "$(unsetopt cshnullglob; setopt nonomatch;
		[[ -d ~foo ]] && echo ok)" ]]

Or:

	[[ -n "$(hash -df ; hash -dm foo)" ]]

The latter is of course very poor when there are a large number of users.

Does anyone know a better way?

-- 
Bart Schaefer                             Brass Lantern Enterprises
http://www.well.com/user/barts            http://www.nbn.com/people/lantern

New male in /home/schaefer:
>N  2 Justin William Schaefer  Sat May 11 03:43  53/4040  "Happy Birthday"



Messages sorted by: Reverse Date, Date, Thread, Author