How to make a global environment variable to change the default action for a terminal command?

I need to start MATLAB with the parameters “env MESA_LOADER_DRIVER_OVERRIDE=i965”. Else I can’t use the hardware opengl functionality. I have already inserted this parameter in the .desktop file, but I would also like to change that if I type “matlab” in the terminal, that it always uses this override. I think that I probably can edit something in .xinitrc or .bashrc, but I am not that familiar with it yet.

Would something like

if [ "matlab" ]; then
    echo env MESA_LOADER_DRIVER_OVERRIDE=i965 matlab
done

work?

Have you considered using an alias? Something like

alias matlb="matlab env MESA_LOADER_DRIVER_OVERRIDE=i965"

Edit: Changes to aliases could be stored in /home/$USER/.bashrc

https://wiki.manjaro.org/index.php?title=Aliases_in_.bashrc

2 Likes

I am just starting to get into all of these advanced settings. Thank you! It works like a charm. Unfortunately not in the python script that starts my matlab server in neovim.

1 Like

Automatically? :face_with_raised_eyebrow: I didn’t think so, Brother. :stuck_out_tongue:


Try changing the name of the alias ─ you’ll have to log out and back in for this to take effect. :arrow_down:

alias matlab="matlab env MESA_LOADER_DRIVER_OVERRIDE=i965" 

Your Python script is probably calling matlab by its given name, and the alias @Wollie gave you used a different name.

You are right, edited my post. :innocent:

1 Like

The default .bashrc includes .bash_aliases which provides a neat bundling up for bash session aliases.

You can add new entries to your session through source.bash_aliases or . .bash_aliases if you like that sort of thing.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.