I need to run a script every time I open WSL Ubuntu 18.04 on Windows 10

Viewed 9220

Every time I open WSL Ubuntu 18.04 on Windows 10 I want to run these settings automatically.


    alias desktop='cd /mnt/c/Users/Dot/Desktop/ai_files'
    export PYTHONPATH=${PYTHONPATH}:${HOME}/ai-safety-gridworlds
    export DISPLAY=localhost:0.0

I tried making .sh script with the following content in /etc/init.d/ but it didn't work.


    #!/bin/bash
    alias desktop='cd /mnt/c/Users/Dot/Desktop/ai_files'
    export PYTHONPATH=${PYTHONPATH}:${HOME}/ai-safety-gridworlds
    export DISPLAY=localhost:0.0

2 Answers

To run these commands every time you open WSL, you will want to append the commands to .bashrc. In bash, run

echo "alias desktop='cd /mnt/c/Users/Dot/Desktop/ai_files'" >> ~/.bashrc
echo "export PYTHONPATH=${PYTHONPATH}:${HOME}/ai-safety-gridworlds" >> ~/.bashrc
echo "export DISPLAY=localhost:0.0" >> ~/.bashrc

To create an environment variable which will be visible for all users on Ubuntu you can create a sh file in /etc/profile.d folder. In example :

sudo vi /etc/profile.d/my_vars.sh && sudo chmod o+r /etc/profile.d/my_vars.sh

then include there your variables. For example:

export ORACLE_HOME="/opt/oracle/instantclient_11_2"

terminate and start wsl again. Variables should be accessible for all users.

Related