How can I set path so it can be read from GUI and command line by the same program?

Black Panther

I installed texlive and I want to add it as an environment variable to my Path so that Emacs AucTeX can read it when I start emacs from the GUI or from the command line. So far I've read that emacs only reads files from ~/.profile.

Therefore my plan is to add texlive to my path in .profile to enable emacs GUI to read it and then source ~/profile from .bashrc in order for emacs that is started inside my non-login interactive GNOME terminal to see the path.

Note: I do not have a .profile file in my home directory, only in my /etc directory, and I'd rather not touch that one, but I have a .bash_profile in my home directory. However I read that .bash_profile is only run for an interactive login session aka console mode which I don't use.

My plan is to create a .profile file in my home directory and do the following:

step 1: Create ~/.profile

Step 2: Add texlive environment variable to path in .profile

export PATH=/usr/local/texlive/2018/bin/x86_64-linux:$PATH
export MANPATH=/usr/local/texlive/2018/texmf-dist/doc/man:$MANPATH
export INFOPATH=/usr/local/texlive/2018/texmf-dist/doc/info:$INFOPATH

Step 3: Source .profile from .bashrc

#Adding this at the bottom or start of .bashrc to source .profile when the terminal is opened.

if [-s ~/.profile]; then;
    source ~/.profile;
fi

I know that there is a lot of apprehension towards sourcing .profile from .bashrc due to the risk of causing an infinte loop. However since I am creating a .profile file from scratch this will not be a problem as it will not contain any code that references .bashrc.

My Questions:

  1. What do you think of my plan?
  2. Do you think it will work?
  3. Do you have any suggestions on how to improve it or perhaps other alternatives

Additional info: My .bashrc only contains code that sources ~/etc/bashrc and one environment variable that was automatically added by Anaconda: export PATH="/home/Fedora_User/Anaconda3/bin:$PATH"

Keep in mind that I know gnome-terminal can be run as an interactive login shell but I have never done this and don't know if it will impact the performance of my terminal sessions.

Zanna

Firstly, note that if you want ~/.profile to be read, you'll need to remove ~/.bash_profile, otherwise ~/.profile will be ignored by Bash.

You are actually overcomplicating this a bit. PATH is set in /etc/environment. It is always exported already, so it does not need to be exported again.

If you make changes to your PATH in ~/.profile they will be inherited by every shell, whether it is a login shell, interactive or otherwise.

Other variables exported in ~/.profile will also be passed into the environment, and will be available in every shell. ~/.profile is read once when you log in to your session, and exported variables stay exported.

Sourcing ~/.profile in ~/.bashrc is a bad idea. ~/.profile sources ~/.bashrc so you will get an infinite loop. Even if ~/.profile does not source ~/.bashrc it is a bad idea to have ~/.bashrc source ~/.profile or any other file with assignments like

PATH=$PATH:/some/other/place

because every time an interactive shell starts another interactive shell the PATH will get extended... you'll end up with your PATH being

/original/path:/some/other/place:/some/other/place:/some/other/place

etc.

Your MANPATH assignment does not need to include $MANPATH but it should start with a leading colon. Please see this question and its answer. By default MANPATH is unset and the correct path is dynamically determined (in some way I don't understand), so including the existing MANPATH does nothing. You may need to start the MANPATH assignment with a colon to avoid preventing the path being determined dynamically. As far as I know, the same goes for INFOPATH

Therefore, I suggest:

Rename ~/.bash_profile ~/.profile

Add the lines:

PATH="$PATH:/usr/local/texlive/2018/bin/x86_64-linux"
export MANPATH=":/usr/local/texlive/2018/texmf-dist/doc/man"
export INFOPATH=":/usr/local/texlive/2018/texmf-dist/doc/info"

Notes that I have appended to the PATH rather than prepending. You can prepend (put $PATH at the end instead of the beginning) if you want to. The first executable found in path lookup is run, so if two programs in different PATH locations have the same name, the one in the directory that comes first (further to the left) in PATH will be run.

Do not add anything to your ~/.bashrc. Environment variables modified, or new variables exported in ~/.profile will be available to every shell and don't need to be additionally set elsewhere.

Also note that you should not source /etc/bash.bashrc in ~/.bashrc, because /etc/bash.bashrc is already sourced by every interactive shell first*, and we use ~/.bashrc to make subsequent adjustments.

*An exception - /etc/bash/bashrc checks that the shell is interactive using an unreliable method - it checks that PS1 is set. If you start a shell unsetting PS1, /etc/bash.bashrc will not be sourced, even though the shell is interactive. Another exception is when the shell is started with --norc, but that's more obvious.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How can I set the each line color or width in SVG path

From Dev

Can a WinForms program be run from command line?

From Dev

How do I build/deploy a Java program so that anyone can open it without an IDE or Command Line?

From Dev

How can I open another command line application in Linux from a Java program?

From Dev

How can I read two variables from a txt file that are on the same line? in python

From Dev

c# console: how can i read piped input from the command line

From Dev

How can I specify the package name when launching a Lisp program from the command line?

From Dev

How do I read arguments from the command line with an MPI program?

From Dev

How can I align my buttons so that they stay in the same line?

From Dev

How can I pass command-line arguments to a Erlang program?

From Dev

Can I set the vim colorscheme from the command line?

From Dev

How can I start octave from the command line and not the GUI?

From Dev

How can I expand a relative path at the command line, with tab completion?

From Dev

How can I hibernate/suspend from the command line and do so at a specific time

From Dev

How can I read and remove meta (exif) data from my photos using the command line?

From Dev

How can I expand a relative path at the command line, with tab completion?

From Dev

How can I hibernate/suspend from the command line and do so at a specific time

From Dev

How can I open a file read-only from command line with emacs/vi/vim

From Dev

How can I read and remove meta (exif) data from my photos using the command line?

From Dev

How can I add a program path to the Windows environment variables for easy command line access?

From Dev

How can I pass all command line arguments to a program in a Makefile?

From Dev

Can a WinForms program be run from command line?

From Dev

How to link to php from xampp installation so i can just use php command instead of full path?

From Dev

How can I read line by line from a variable in bash?

From Dev

How can I reference the same path from one command to the next?

From Dev

linux: how can i open a gui program like google-chrome from the command line so that it stays open even after teminal closes

From Dev

how can i read line by line from a variable in bash

From Dev

How can I change this code so it prints on the same line?

From Dev

How can I get my C program to read more than one line of text from a file?

Related Related

  1. 1

    How can I set the each line color or width in SVG path

  2. 2

    Can a WinForms program be run from command line?

  3. 3

    How do I build/deploy a Java program so that anyone can open it without an IDE or Command Line?

  4. 4

    How can I open another command line application in Linux from a Java program?

  5. 5

    How can I read two variables from a txt file that are on the same line? in python

  6. 6

    c# console: how can i read piped input from the command line

  7. 7

    How can I specify the package name when launching a Lisp program from the command line?

  8. 8

    How do I read arguments from the command line with an MPI program?

  9. 9

    How can I align my buttons so that they stay in the same line?

  10. 10

    How can I pass command-line arguments to a Erlang program?

  11. 11

    Can I set the vim colorscheme from the command line?

  12. 12

    How can I start octave from the command line and not the GUI?

  13. 13

    How can I expand a relative path at the command line, with tab completion?

  14. 14

    How can I hibernate/suspend from the command line and do so at a specific time

  15. 15

    How can I read and remove meta (exif) data from my photos using the command line?

  16. 16

    How can I expand a relative path at the command line, with tab completion?

  17. 17

    How can I hibernate/suspend from the command line and do so at a specific time

  18. 18

    How can I open a file read-only from command line with emacs/vi/vim

  19. 19

    How can I read and remove meta (exif) data from my photos using the command line?

  20. 20

    How can I add a program path to the Windows environment variables for easy command line access?

  21. 21

    How can I pass all command line arguments to a program in a Makefile?

  22. 22

    Can a WinForms program be run from command line?

  23. 23

    How to link to php from xampp installation so i can just use php command instead of full path?

  24. 24

    How can I read line by line from a variable in bash?

  25. 25

    How can I reference the same path from one command to the next?

  26. 26

    linux: how can i open a gui program like google-chrome from the command line so that it stays open even after teminal closes

  27. 27

    how can i read line by line from a variable in bash

  28. 28

    How can I change this code so it prints on the same line?

  29. 29

    How can I get my C program to read more than one line of text from a file?

HotTag

Archive