0

Calling export MYVAR=/path/to/whatever from .bashrc obviously works for bash but not for the sh shell. Unfortunately, the Matlab launcher seems hell-bent on using sh and not bash. As such, the simplest way to export an environment variable such that it is accessible from Matlab would be to export said variable to sh.

How can I persistently export an environment variable to sh?

Louis Thibault
  • 1,187
  • 5
  • 15
  • 24
  • @muru I think [Where to declare environment variables?](http://askubuntu.com/questions/4667/where-to-declare-environment-variables) is not sufficiently answer the problem for the dash. – A.B. Apr 24 '15 at 08:36
  • 1
    @A.B. yes it is. `/etc/environment` and `.pam_environment` apply everywhere. – muru Apr 24 '15 at 08:49
  • @muru, that's not obvious to everyone, though. This question has the merit of being explicit and narrower in scope. – Louis Thibault Apr 24 '15 at 09:16
  • 1
    @blz I don't see a narrow scope as a merit. And the solution to lack of obviousness is to make it obvious, not post a new question. – muru Apr 24 '15 at 09:17

1 Answers1

1

Perform the following steps in the current shell (tested with zsh and bash), not in dash:

  1. Open your .profile:

    nano ~/.profile
    
  2. Add this line

    ENV=$HOME/.dashrc; export ENV
    
  3. Open .dashrc

    nano ~/.dashrc
    
  4. Add this line:

    export MYVAR=/path/to/whatever
    
  5. Finally reload .profile

    . ~/.profile
    

    or log out and then log in again.

Now start dash with:

  • sh

    or

  • dash

and type

$ echo $MYVAR
/path/to/whatever
Fabby
  • 34,341
  • 38
  • 97
  • 191
A.B.
  • 89,123
  • 21
  • 245
  • 323