LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Bash macro expansion in aliases (https://www.linuxquestions.org/questions/linux-software-2/bash-macro-expansion-in-aliases-731023/)

jhwilliams 06-05-2009 06:51 PM

Bash macro expansion in aliases
 
I thought I used to know how to do this, but appear to have forgotten. I beg re-enlightenment from the elders in the Community.

Code:

alias some_command='./some_command --with-custom-flags && echo !!'
What I want the above to do is print out my alias (the !! history substitution) so that I know exactly what __real__ command was issued. But the above just prints the literal !! without doing a substitution.

Thoughts? Ruminations? Solutions?

i92guboj 06-05-2009 07:54 PM

Use double quotes instead of single ones. Single quotes prevent any expansion.

However, that's not going to help you, if I am not mistaken it will only print the name of the alias (because that's the last command you issued, duh?

jhwilliams 06-10-2009 04:13 PM

The last command issued would be the one before the echo, evaluated inside the alias string, ostensibly. However, neither your proposal nor that I've just stated are accurate. The !! evaluates before everything in the line, so it gets whatever you'd typed before:
Code:

$ This is the last thing I typed.
$ alias ham="echo ham && echo !!"

Results in
This is the last thing I typed.


All times are GMT -5. The time now is 04:13 AM.