I am attempting to create a script that shows how much memory every user on the system is using in their home directory. Everything was going smooth till I started using the du -sh command to start pulling information about specific users. I attempt to run:
du -sh ~currentUser
enter code here
I understand how the command works in command line. How do I get it to work while using a variable username? Below reguser is dummy account I have on my system I use to screw around with.
:/home/reguser/Documents# du -sh ~reguser
Gives output of
71M /home/reguser
~expands to/home/? It's supposed to expand to the current value of theHOMEenv var.~alone expands to$HOMEbut~usernameexpands to homedir of that user fromgetpwnam(equivalent togetent passwd, as in glenn's answer) and nowadays distros usually default user homedirs to/home/$user