1

I have two Ubuntu VM's where one is running on VirtualBox (Ubuntu 18.04) and the other is on WSL 1 (Ubuntu 20.04).

#!/bin/bash

dir=~ echo $dir

When I run the above shell script without the sudo, both VM's print my own /home/user directory. But when run this with sudo, VirtualBox instance prints /home/user and the WSL instance prints /root. I'm not sure why this happens and if there is any relevance to VM's.

I need this to print the /home/user directory in the WSL instance even when running as sudo. I achieved this by running this as sudo -E but I don't know if that's the best method. Can someone explain why do I get different behaviours in different environments?

0 Answers0