I need to get user home folder. At the moment I'm using this
home=$(eval echo ~$user)
Content of $user is provided by the caller, so not trusted value. Is the use of the eval dangerous here? If yes (probably), how to solve it without it?
On systems that have it, you can use getent(1):
$ getent passwd "$username" | cut -d: -f 6
/path/to/user/home
Make sure to check for empty results though.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With