1

I have exported the PATH but once I switch to a different terminal or reboot Debian, $PATH is reset. Here are the steps I take:

~$ vim scripts.sh

#!/bin/bash
echo "Hello"

I save it as mybash.sh and chmod with 755. Then I move it to my /root/scripts directory.

Then:

~$ export PATH=$PATH:~/root/scripts

and it works, but once I reboot Debian, close or switch into another terminal, mybash.sh cannot be called.

Why doesn't it store PATH permanently?

2 Answers2

3

You can add the line to the /etc/enviroment file like this:

PATH=$PATH:~/root/scripts

or

Edit your ~/.bashrc and add your line here like this:

export PATH=$PATH:~/root/scripts
krt
  • 1,239
  • 2
    No. You misspelled /etc/environment, the syntax you used doesn't work there (variable expansion only works in shell scripts, this is not a shell script), and .bashrc only works partially (it sets the variable only in programs launched from a terminal). None of this is correct. – Gilles 'SO- stop being evil' May 21 '15 at 23:09
0

Edit your ~/.bashrc file and add your export PATH line to it.

Lambert
  • 12,680
  • No. .bashrc only works for programs launched from a terminal. – Gilles 'SO- stop being evil' May 21 '15 at 23:09
  • @Gilles, I quote from the question: "...into another terminal...", and therefor do not understand your comment. Can you please clarify your comment? – Lambert May 22 '15 at 07:50
  • @Lambert .bashrc is only read in a terminal. So modifying PATH there will only take effect in programs that are launched via a terminal. That takes care of the specific example where the program is launched from a terminal, but not of the general case where the program is launched from somewhere else. – Gilles 'SO- stop being evil' May 22 '15 at 08:28
  • 1
    @Gilles, thanks for your explanation. The OP asked how to set the PATH variable permanently for new terminals so the answer to that is, in my opinion, still valid. I agree that you can not rely on it in all cases (ie. when calling from a custom binary started from the desktop, of using a different shell like zsh) but in this case it is obvious that bash is being used and that the script is called from a terminal window. – Lambert May 22 '15 at 08:53