Timeline for How to correctly add a path to PATH?
Current License: CC BY-SA 3.0
13 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Mar 19, 2022 at 1:40 | comment | added | iconoclast | ahhh, I see what you mean... "fail silently" from the point of view of the person issuing the command at the moment, even though it succeeds at ignoring non-existent directories (and therefore succeeds from the original programmer's point of view) | |
| Mar 19, 2022 at 0:49 | comment | added | G-Man Says 'Reinstate Monica' |
@iconoclast: We’re not understanding each other. Including: I don’t understand your question. But I guess your question is founded on a misunderstanding of what I said. To clarify, [ -d "$1" ] certainly will fail (i.e., evaluate to false) if the directory doesn’t exist. But look at the big picture: if [ -d "$1" ] … ; then (add to PATH) fi — there’s no else clause. If the directory doesn’t exist, the function will not change the PATH — but it won’t issue an error message, so the user doesn’t know that it failed, and doesn’t understand why their program is “not found”.
|
|
| Mar 18, 2022 at 21:47 | comment | added | iconoclast |
@G-ManSays'ReinstateMonica': why won't the [ -d "$1" ] catch the case of a non-existent directory? I haven't tested the code (because I have more own function which I prefer) but it seems like it should....
|
|
| Mar 15, 2022 at 20:22 | comment | added | G-Man Says 'Reinstate Monica' |
(Cont’d) … (3) Your pathrm will fail if the argument contains ;. Again, you ‘‘shouldn’t’’ create directories with semicolons in their names, but you should try harder to handle it (or at least document it as a weakness of your code). (4) And ;::;:; is fun to read … NOT! (5) Your pathrm also fails silently if you mistype the argument.
|
|
| Mar 15, 2022 at 20:22 | comment | added | G-Man Says 'Reinstate Monica' |
(1) echo $PATH can mess up if $PATH contains field separators or glob characters. Yeah, sure, you ‘‘shouldn’t’’ create directories with field separators or glob characters in their names, but why not handle that case correctly, when it’s so easy to do? (2) Why the silent failure if the directory doesn’t exist? If you type pathadd "/opt/newprogran/bin" and then newprogram, and you get a “command not found” error, how long will you scratch your head before you notice that you misspelled the directory in the pathadd command? … (Cont’d)
|
|
| Feb 1, 2021 at 11:02 | comment | added | Brett Ryan |
That check is already present @RogerDahl , the use of -d
|
|
| Feb 1, 2021 at 0:47 | comment | added | Roger Dahl | I've found it useful to add to this a check that the path exists as well, and silently ignore the call if it doesn't. | |
| Jul 26, 2019 at 19:03 | comment | added | Wildcard | Related and cleaner approach to check for presence of a directory in your PATH: unix.stackexchange.com/a/32054/135943 | |
| S May 10, 2017 at 13:15 | history | suggested | Mark | CC BY-SA 3.0 |
add removal of trailing slash to grep command too, as a bugfix
|
| May 10, 2017 at 11:49 | review | Suggested edits | |||
| S May 10, 2017 at 13:15 | |||||
| Apr 12, 2017 at 3:08 | history | edited | Brett Ryan | CC BY-SA 3.0 |
added 432 characters in body
|
| Mar 17, 2016 at 23:33 | review | First posts | |||
| Mar 17, 2016 at 23:42 | |||||
| Mar 17, 2016 at 23:28 | history | answered | Brett Ryan | CC BY-SA 3.0 |