I'm sure this has been asked before but I can't find anything. We have inscrutable login names on a shared machine and want to use shell variables to substitute the hard-to-remember login names for people's real names.
For example, let's say Omar's login name is xyz123. I can do this:
$ omar=xyz123 $ echo ~$omar and output looks fine:
~xyz123 but if I type this:
$ ls ~$omar there is an error:
ls: cannot access ~xyz123: No such file or directory I think it's because tilde expansion happens before variable expansion but can't figure out how to get around this.
Perhaps this answer is related although I'm not sure: How to manually expand a special variable (ex: ~ tilde) in bash
~xyz123but it is not the path toxyz123home directory.evalwon't endear me to the security folks — and there's no blame to them for that.omar, in which case you'll just use~, or the script will be run as root, who can just usesuto becomeomaras necessary.cdable_varsoption instead; add a variable likeomarhome=/home/omar(look it up manually once and store the value in the variable), thencd omarhomewill be equivalent tocd "$omarhome". (Other commands, of course, will have to use the variable more explicitly, e.g.ls "$omarhome".)