have to determine all users home directories - tilde scripting problem

后端 未结 6 1530
臣服心动
臣服心动 2021-01-03 04:04

Assume someuser has a home directory /home/someuser

NAME=someuser

In bash - what expression to I use combining tilde (~) and $NAME to return the users home d

6条回答
  •  无人及你
    2021-01-03 04:40

    Interesting difference between bash and csh, where ~$VARNAME actually does what you'd expect!

    This is ugly, but it seems to work in bash:

    homedir=`eval "echo ~$USERNAME"`
    

    Now $homedir holds the home directory associated with $USERNAME.

提交回复
热议问题