Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> Directory names are far from unique, a misfiring 'cd tmp' or 'cd src' can easily lead to nasty surprises, even without 'rm' ever getting involved at all.

I hear what you're saying, though I'm not really persuaded by this argument. When you 'cd' into a directory along your CDPATH, Bash will print out where you end up when you arrive. Here's an example of what I mean (easier to see than explain):

    circe ~ ❯❯ cd bin
    circe bin ❯❯ cd ithaca
    /Users/circe/code/ithaca
    circe ithaca [master•] ❯❯ 
The regular cd simply takes me where I asked. When I cd and use CDPATH (in the second case), I get told where I end up. Sure, there might be four or five different 'ithaca' folders on various machines and even on one machine, but I think that extra print-out really makes it unlikely that I will get confused.

> And you do know that CDPATH also affects shell scripts, right?

No, I'm embarrassed to say, I never thought of this. And this part does sound like a potential problem. When I write Bash scripts, I always use full paths, but I see where my having CDPATH set puts me at danger from other people's scripts. Technomancy gives a concrete example above. Although I think this is bad practice on their part (not to use full paths), I appreciate the warning.



Consider applying for YC's Summer 2026 batch! Applications are open till May 4

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

Search: