Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 12-14-2014, 11:28 AM   #1
LQ Newbie
Registered: Dec 2014
Posts: 2

Rep: Reputation: Disabled
obtain replacement value of bash alias as executed

Given I have
alias gs='git status'
in one of my bash initialization files (e.g. .bash_profile), and that I execute the command
from my prompt, how can I access the value of the command line 'as executed' (in this case
'git status'
) and not as entered (in this case
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!

Last edited by webapphero; 12-14-2014 at 11:30 AM.
Old 12-15-2014, 10:52 AM   #2
LQ Addict
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,896

Rep: Reputation: 352Reputation: 352Reputation: 352Reputation: 352
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.

type ll
ll is aliased to `ls -lh --color=auto'
alias ll
alias ll='ls -lh --color=auto'
Or, if you prefer,
echo $(type ll)
echo $(alias ll)

Last edited by bigrigdriver; 12-15-2014 at 10:58 AM.
Old 12-15-2014, 11:48 AM   #3
LQ Newbie
Registered: Dec 2014
Posts: 2

Original Poster
Rep: Reputation: Disabled
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'?


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
bash script to display alias commands and un-alias any less than 12 characters bani Linux - Newbie 5 01-19-2014 01:34 PM
Bash - obtain contents of file after variable substitution Chaos Daemon Linux - General 6 09-21-2011 12:37 PM
Bash script does not behave the same when executed through /etc/rc.local bmpenev Linux - General 1 06-05-2009 12:46 PM
bash script runs different when cron executed jalder85 Linux - Server 4 02-20-2009 12:53 PM
how is my program executed by bash and the kernel aheak123 Programming 2 08-20-2006 06:41 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:16 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration