Use OneDrive to Share WSL Commands Between Accounts and Machines

This blog post explains how to make commands available easily to multiple Windows accounts and Windows Subsystem for Linux (WSL) accounts on multiple machines that share access to a common OneDrive.

If you use commands that are not availble to WSL, such as if you download command line tools for Windows or write your own shell scripts, then to make those commands available to any Windows and WSL accounts on any machines that can access a shared OneDrive. Store the commands in a directory of the OneDrive and create symbolic links from multiple WSL home directories to a directory a OneDrive available to multiple Windows and WSL accounts (potentially on separte machines).

When you start a Bash shell, it first invokes the commands in the “hidden” .profile file in your home directory, and then invokes the commands in the “hidden” .bashrc file.

The default .profile under WSL checks for the existence of a directory (as determined by the $HOME environment variable) named bin (hard-coded in .profile) under that home directory. If bin exists and the system recognizes it as a directory, then .profile add $HOME/bin to the $PATH environment variable. This lets you invoke commands in the bin directory by name rather than specifying a full or relative path or by changing the working directory to the $HOME/bin directory.

You can store commands in a OneDrive folder and create a symbolic link from $HOME/bin on any number of systems to that directory on the OneDrive. Then you can put executables, scripts, and any other commands in that directory.

On my OneDrive, I have an directory named wslbin where I store commands that I use from WSL. I use the following code to create a symbolic link from $HOME/bin to the wslbin on my onedrive, which sits under C:\data on my Windows machine. This first changes the current working directory to the home directory ($HOME) and then creates the symbolic link.

cd
ln -s /mnt/c/data/onedrive/wslbin bin
Console showing creation of symbolic link and results

One thought on “Use OneDrive to Share WSL Commands Between Accounts and Machines

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: