Monday, February 7, 2011

Potential Dangers of ALIASing a Unix Command Starting with "."?

I'd like to use alias to make some commands for myself when searching through directories for code files, but I'm a little nervous because they start with ".". Here's some examples:

$ alias .cpps="ls -a *.cpp"

$ alias .hs="ls -a *.h"

Should I be worried about encountering any difficulties? Has anyone else done this?

  • I wouldn't use '.' to begin your aliases because it's next to '/' and you could hit the two together by mistake and accidentally run an executable in your current directory (especially if you use tab completion).

    Jonathan Leffler : What is the likelihood of their being a command `./cpps` in the current directory - that does any damage? I don't think I've fumble-fingered the dot and slash keys - I mistype plenty of things, but don't recall that being a problem.
    agtb : If you're compiling executables then there may well be something that starts with a 'c' in the current working directory. I think as a general rule that if you can type faster than your terminal displays (e.g. using a laggy SSH connection) and use tab completion e.g. ./c that would be a _potential_ danger. I don't know many people who spend time in shells who don't have a horror story to share about when they made a typo or used ^substitution^mistake and wreaked merry hell.
    From agtb
  • I doubt that there's any technical problem though it's likely to be confusing to anyone who has used Unix for a long time. In my world commands don't have dots in them and file names don't have spaces or upper case letters!

  • What is the advantage of putting the dot in the names? It seems like an unnecessary extra character. I'd just use the base names (hs and cpps) for the aliases.

    I suppose that it might be argued that the dot indicates that the command is an alias - but why is that distinction beneficial? One of the great things about Unix was that it removed the distinction between hallowed commands provided by the O/S and programs written by the user. They are all equal - just located in different places.

    I don't see any real dangers with using aliases that start with a dot. It would never have occurred to me to try; I'm mildly surprised that they are allowed. But given that they are allowed, there is no real risk involved that I can see.

0 comments:

Post a Comment