首页 > 解决方案 > 每次在 Windows 10 上打开 WSL Ubuntu 18.04 时,我都需要运行一个脚本

问题描述

每次我在 Windows 10 上打开 WSL Ubuntu 18.04 时,我都想自动运行这些设置。


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

我尝试在 /etc/init.d/ 中使用以下内容制作 .sh 脚本,但没有成功。


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

标签: shstartupubuntu-18.04windows-subsystem-for-linux

解决方案


要在每次打开WSL时运行这些命令,您需要将这些命令附加到.bashrc. 在 bash 中,运行

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

推荐阅读