DamionGans / ubuntu-wsl2-systemd-script

[Does not work anymore!] Script to enable systemd support on current Ubuntu WSL2 images
1.56k stars 383 forks source link

Avoid false positive to get home directory #12

Closed hnakamur closed 4 years ago

hnakamur commented 4 years ago

First of all, thanks for creating and sharing a great script to run systemd!

I noticed https://github.com/DamionGans/ubuntu-wsl2-systemd-script/commit/bb2822c776512345aa597bab9e51d04a4c346239 is somewhat avoiding false positive but not perfect (ex: ^root matches rootfoo).

Another solution would be adding colon after $SUDO_USER and adding BEGIN for settings FS like below:

$ SUDO_USER=root; USER_HOME="$(getent passwd | awk 'BEGIN { FS=":" } /^'"$SUDO_USER"':/ {print $6}')"; echo $USER_HOME
/root

However I think this is clearer.

$ SUDO_USER=root; USER_HOME="$(getent passwd | awk -F: '$1=="'"$SUDO_USER"'" {print $6}')"; echo $USER_HOME
/root
DamionGans commented 4 years ago

Sharp eye! Thanks for your contributions!