Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

5
  • 3
    This is the best answer because it doesn't expose you to other commands on your path being hijacked. All of the other answers here risk running other executables as root. Commented Jan 14, 2021 at 14:08
  • Unless the command you're using calls other commands that it expects to find in $PATH - then you want to be "hijacked", and so the other answers are better. Commented Jan 18, 2022 at 4:11
  • @DaveMorse Yes, in that sense, my example is not secure but then the question of How to make "sudo" preserve $PATH? is not a secure idea either. Commented Jan 18, 2022 at 9:16
  • using absolute path avoid PATH problem. in general purpose a smart move Commented Oct 11, 2022 at 7:07
  • I don't know that it's the best answer. It's a good answer. The reason why is some scripts start with something like #!/usr/bin/env python3 and this answer won't help make sure you get the right python3, like for a virtual environment. Commented Jul 12, 2023 at 15:30