I’ve made several aliases for my convenience.But now I need to be helpful by sending a useful command and it is full of aliases.I’ve tried doing type u but all it returns is
up && ap upgrade -y --show-progress && r && ap check && ap autoclean
These are all aliases in u:
alias a='alias' a ap='apt-get' a r='ap autoremove -y' a up='ap update'
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
Press Ctrl-Alt-e with a command using your aliases written (ready to run) and Bash will expand it. Ctrl-Alt-e is the default binding for the shell-expand-line readline command.
Each time you push Ctrl-Alt-e Bash will expand one layer of alias, so push it repeatedly until your command is expanded as far as you need.
If your Meta key is not Alt, substitute it instead, or press Escape Ctrl-e.
There is also an alias-expand-line function which is not bound by default, which only expands aliases.
Method 2
I posted a similar question on StackOverflow (probably should have posted here on Unix & Linux).
My solution was to write a bash function:
xtrace() {
local eval_cmd
printf -v eval_cmd '%q' "${@}"
{ set -x
eval "${eval_cmd}"
} 2>&1 | grep '^++'
return "${PIPESTATUS[0]}"
}
So xtrace u will print out something like:
++ apt-get update ++ apt-get upgrade -y --show-progress ++ apt-get autoremove -y ++ apt-get check ++ apt-get autoclean
Keep in mind that this actually executes whatever alias you pass to it, so if you don’t want to execute u, then @MichaelHomer’s solution is the better way to go. Also, because of your && chain, if any one of the commands in your alias does not return 0, then execution will stop and you will only see the expanded aliases up to that point.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0