append to an existing alias
I didn't think this would be so hard to find an answer to, but I'm coming up with nothing in my searches.
I simply want to append a flag onto whatever the existing alias for a command is. For example Code:
$ alias ls Code:
alias ls='ls -d -l' |
don't think so.
You are asking an alias to work like a variable substitution, but that isn't what an alias is. PS. it would also make it impossible to have different commands use the same utility in different ways: alias ll="ls -l" alias la="ls -a" and the ever famous alias ls="ls -ltr" |
I'm not asking for the alias itself to function any different than it already does, I'm just asking for the alias program to expand the command you pass it (using any existing aliases) before setting the alias, rather than just blindly overwriting the alias with the literal string you pass it.
Once the alias is set, it would behave just like normal, it's just the setting of the alias that would be different. If it's not possible, then I guess I'm going to have to do some ugly string manipulation to get that kind of functionality. |
Quote:
Quote:
alias ls="ls -ltr" so how would you define alias la="ls -a" When it would always come out as "ls -ltr -a". You couldn't define the alias you wanted. Quote:
And it is done relatively frequently in complex shell scripts. The commands are defined as variables, with other variables used to specify options, then combined/merged in different ways to define specific results. One common such variable is CC. $CC is the C compiler... except when it happens to be the C++ compiler instead.This is heavily done in Makefiles for instance - which pass the resulting command to the shell... |
Quote:
If you run alias ls="ls -ltr" alias la="ls -a" When you run "la", it's going to run "ls -ltr -a". I nest aliases like that all the time, works great. In fact that's the exact kind of behavior I'm looking for here, just without having to define a second command to get it. If you wanted la to really mean "ls -a", with no prior aliases jumping into the mix, you would define it as alias la="\ls -a" Quote:
|
Oh well. Personally, I don't like aliases at all - I find it hides things I need to know, and causes problems when they disappear for some reason - it ties you to a specific command interpreter.
|
All times are GMT -5. The time now is 11:19 AM. |