0

I installed Ubuntu 17.04 and copied my custom scripts into ~/bin. Then I made all files in that directory executable, via chmod. I double-checked in GUI, and the files are executable.

I checked ~/.profile, and it already contains the following lines (which are NOT commented out):

if [ -d "$HOME/bin" ]; then
    PATH="$HOME/bin:$PATH" 
fi

However, when I try to run a script (in that directory) by typing my-script-name in terminal, I get "command not found" error, yet when I type ~/bin/my-script-name, then it runs properly.

I was able to run custom scripts from ~/bin directory in this way in 16.04 LTS, but it's not working for me in 17.04. What do I need to do to make this work? Does 17.04 no longer check that directory?

  • if a .bash_profile exists; .profile is ignored. there are a series of files that are run on first login, any logins etc.... – guiverc Aug 26 '17 at 3:01
  • what output of export | grep $PATH you get? – Redbob Aug 26 '17 at 3:07
  • @Redbob, the output of "export | grep $path" is the following: declare -x PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin" – Be Brilliant Aug 26 '17 at 3:20
  • @guiverc, I have a file named .profile and a file named .bashrc in /home/myusername/, but I do not have a file in that directory called .bash_profile. – Be Brilliant Aug 26 '17 at 3:30
  • @Redbob I think you mean export | grep '^declare -x PATH=' – wjandrea Aug 26 '17 at 4:44
3

~/.profile is automatically sourced only on login. You have to log out and back in for changes to take effect.

You can also run source ~/.profile in a terminal, but the changes will take effect only for that terminal.

When you ran exec -l bash, that opened a login shell, but only in that terminal.

0

I read somewhere to try running exec -l bash, and that fixed the problem within that terminal window, as long as it was open. However, when I closed the window and tried running scripts within a new window, I had the same problem, again.

At that point, I tried rebooting, and the problem is fixed, although I really don't understand why. When I run export | grep $PATH, I now get the following:

declare -x PATH="/home/myusername/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin"

So it's possible that running exec -l bash and then rebooting may have fixed the problem. I would appreciate any comments or explanation as to whether this was a relevant course of action, or whether it was a random fluke that was fixed by reboot.

0

If you want to customize your path to execute scripts in terminal session , is preferable to put Path declarations in your ~/.bashrc file.

So, edit your ~/.bashrc file and add at the end of this file, the following line:

export PATH=$PATH:$HOME/bin

or

export PATH=$PATH:~/bin

so everytime you open a terminal session, you will have PATH properly configurated. You won't have to reboot or relogin your session for it!!

  • 1
    This is not going to work: PATH=$PATH:$HOME/bin/my-script-name. Items in the PATH need to be dirs. – wjandrea Aug 28 '17 at 4:49
  • it's true, @wjandrea. I corrected it – Redbob Aug 28 '17 at 11:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.