LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   obtain replacement value of bash alias as executed (https://www.linuxquestions.org/questions/linux-newbie-8/obtain-replacement-value-of-bash-alias-as-executed-4175528241/)

webapphero 12-14-2014 10:28 AM

obtain replacement value of bash alias as executed
 
Given I have
Code:

alias gs='git status'
in one of my bash initialization files (e.g. .bash_profile), and that I execute the command
Code:

'gs'
from my prompt, how can I access the value of the command line 'as executed' (in this case
Code:

'git status'
) and not as entered (in this case
Code:

'gs'
which is what it shows in the history file).

The reason I'm interested is because I want to be able to share portions of my history file with others who won't know about the particular aliases I have setup on my system. I'm trying to figure out a way to access the value of the last command line as executed, not entered. Thanks!

bigrigdriver 12-15-2014 09:52 AM

I know of two ways to do that: type and alias.

For exampls: my alias for a long list ls -l is ll. In a console, try it like this: type ll or alias ll, and get the result.

Code:

type ll
ll is aliased to `ls -lh --color=auto'

Code:

alias ll
alias ll='ls -lh --color=auto'

Or, if you prefer,
Code:

echo $(type ll)
echo $(alias ll)


webapphero 12-15-2014 10:48 AM

Thanks @bigrigdriver. That's helpful.

I'm still looking for a way to get at the entire previous command line as executed, if there is such a value, but your reply helps me down an alternative path if there is no such value stored by the shell.

Regarding alias and type, I'm curious as to the cleanest, most direct way to get at the substitution value itself. With alias gs='git status' how can I get back just 'git status'?


All times are GMT -5. The time now is 11:23 AM.