views:

76

answers:

3

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?

+1  A: 

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).

agtb
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.
Jonathan Leffler
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 <tab> <enter> 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.
agtb
+1  A: 

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!

Stephen Darlington
+2  A: 

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.

Jonathan Leffler