Rogster
Rogster

Reputation: 49

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

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

Upvotes: 4

Views: 14379

Answers (3)

Ben in CA
Ben in CA

Reputation: 851

From root, you can run:

nano .bashrc

And then at the bottom, enter your command(s), e.g., in my case:

sudo -S <<< "password" service redis-server restart

This worked on Ubuntu as WSL on Windows 10

Upvotes: 0

Przemyslaw S.
Przemyslaw S.

Reputation: 1

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.

Upvotes: 0

Ross Douglas
Ross Douglas

Reputation: 120

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

Upvotes: 5

Related Questions