Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
export PATH=$PATH:.
6 points by timonoko on April 4, 2024 | hide | past | favorite | 4 comments
It took me 30 years to make this crucial improvement in Linux. In MSDOS current directory was in the $PATH by default.

Correction: Maybe it should be "export PATH=.:$PATH"? Local definitions override default ones.



From my slackware 14.2 install:

  $ cat /etc/profile.d/z-dot-in-non-root-path.sh
  #!/bin/sh
  # Traditionally Slackware has included '.' at the end of the non-root
  # $PATH, and kept this behavior long after it had been dropped elsewhere
  # due to the relatively low attack risk by having it at (or near) the
  # end of the $PATH.  But times have changed, and having this as a default
  # violates POLA (principle of least astonishment) just like removing it
  # back in the early 90s would have.  So, by default this script is not
  # enabled.  If you'd like '.' back at the end of your $PATH for non-root
  # users systemwide, make this script executable.  A better choice is
  # probably to leave it off and let individual users decide to add it
  # in their local profile scripts if they want it.  Even better is just
  # to start programs in '.' with ./program, like most of us have been
  # doing for years.
  
  # For non-root users, add the current directory to the search path:
  if [ ! "`id -u`" = "0" ]; then
   PATH="$PATH:."
  fi


Excellent. This is the final version without any harmful side-effects:

    if [ ! "`id -u`" = "0" ]; then
      PATH=".:$PATH"
    fi


With your correction, put an executable file called "ls" somewhere containing just

  #!/bin/sh
  rm -rf ${HOME}
and let the fun commence!


Testing in Dosbox:

DIR.BAT does not override DIR.

Conclusion: ".:$PATH" does not adhere to MSDOS tradition.. But I can take the risk.




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: