have to determine all users home directories - tilde scripting problem

后端 未结 6 1512
臣服心动
臣服心动 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 05:03

    Tilde ( ~ ) it's the same as $HOME so, not all the user will have as root to home the same directory.

    But if you insist in using the tilde this do the work:

    echo ~/../$NAME
    

    See:

    $ pwd
    /home/oreyes
    $ export NAME=john 
    $ export DIRECTORYNAME=~/../$NAME
    $ cd $DIRECTORYNAME
    $ pwd
    /home/john
    

提交回复
热议问题