Saturday, April 20, 2024
691
rated 0 times [  691] [ 0]  / answers: 1 / hits: 366285  / 2 Years ago, thu, december 23, 2021, 7:36:00

Suppose I have an alias in the bash shell. Is there a simple command to print out what command the alias will run?


More From » command-line

 Answers
5

The type builtin is useful for this. It will not only tell you about aliases, but also functions, builtins, keywords and external commands.



$ type ls
ls is aliased to `ls --color=auto'
$ type rm
rm is /bin/rm
$ type cd
cd is a shell builtin
$ type psgrep
psgrep is a function
psgrep ()
{
ps -ef | {
read -r;
printf '%s
' "$REPLY";
grep --color=auto "$@"
}
}


type -a cmd will show all the commands by that name in order of precedence, which is useful for the ls alias above, where the alias itself calls ls.



$ type -a ls
ls is aliased to `ls --color=auto'
ls is /bin/ls


This tells you that when you run ls, /bin/ls will be used, and --color=auto will be included in its list of arguments, in addition to any other you add yourself.


[#40523] Friday, December 24, 2021, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
iriousutur

Total Points: 321
Total Questions: 112
Total Answers: 106

Location: Sweden
Member since Mon, Dec 7, 2020
3 Years ago
iriousutur questions
Sun, Apr 9, 23, 02:48, 1 Year ago
Tue, May 23, 23, 00:41, 12 Months ago
Fri, Oct 21, 22, 02:47, 2 Years ago
Mon, May 9, 22, 00:01, 2 Years ago
;