I'm setting up a completely new, fresh Ubuntu 16.04 Minimal system, and have run into a weird problem. Even after adding $HOME/bin to the $PATH, bash can't seem to find any of the scripts in it, at least for root.

I have logged out several times and even restarted the machine once. The path is being set by a one-line script in /etc/profile.d: export PATH="$PATH:$HOME/bin".

root@Pioneer ~ # echo $PATH
root@Pioneer ~ # ls -la /root/bin
total 36
drwxr-xr-x 2 root root 4096 Feb  6 16:04 .
drwx------ 8 root root 4096 Feb  6 16:03 ..
-rwxr-xr-x 1 root root  174 Jan  5  2017 newuser
-rwxr-xr-x 1 root root  236 Nov  3  2015 own
-rwxr-xr-x 1 root root   87 May  6  2017 re-dns
-rwxr-xr-x 1 root root   57 May 10  2016 re-ftp
-rwxr-xr-x 1 root root   89 Oct 20  2015 re-mail
-rwxr-xr-x 1 root root   42 Oct 19  2015 re-smb
-rwxr-xr-x 1 root root   65 Oct 19  2015 re-web
root@Pioneer ~ # newuser
-bash: newuser: command not found

/root/bin/newuser works, as does cd /root/bin && ./newuser.

There are no trailing spaces in the name:

# ls -lb /root/bin/newuser
-rwxr-xr-x 1 root root 174 Jan 5 2017 newuser

Root's home is indeed /root:

# getent passwd root
getent: root:x:0:0:root:/root:/bin/bash 

closed as off-topic by Stephen Kitt, terdon Feb 7 at 11:41

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions describing a problem that can't be reproduced and seemingly went away on its own (or went away when a typo was fixed) are off-topic as they are unlikely to help future readers." – Stephen Kitt, terdon
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 3
    And presumably /root/bin/newuser works as expected, right? – terdon Feb 6 at 15:49
  • It is Ubuntu. How do you run as root? Do you use sudo -s or sudo -i? Maybe it works better if you use the latter command, sudo -i. – sudodus Feb 6 at 15:54
  • /root/bin/newuser works, as does cd /root/bin && ./newuser. – Modus Operandi Feb 6 at 15:55
  • 3
    Since that newuser script is so small, would you mind showing what it contains? And also let us know whether you have a newuser shell function or alias. – Kusalananda Feb 6 at 17:49
  • 1
    What if there is some unprintable character in $PATH? You cannot spot it with echo $PATH; you need printf '%s' "$PATH" | xxd or so. – Kamil Maciorowski Feb 6 at 19:08

Thanks to terdon for the tip; by using strace -e stat bash -c "newuser" 2>&1 | grep /root/bin I discovered that an invisible carriage return had somehow wedged itself before the the closing quote mark in the profile script, making the actual path /root/bin\r. I erased and re-typed the path and it works now.

  • Just out of curiosity, how did you manage to wed it there? Was the text copied from a Microsoft Windows program? – DaBler Feb 8 at 17:29
  • 1
    Yes. I was using a Windows PC to remotely setup a new Linux server while copying parts of config from an older one, and since edits went through windows Notepad, that must be how the CR got in there. – Modus Operandi Feb 9 at 19:06

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