Can I make bash stop parsing and validating a certain alias?

8

2

I'm using Fedora 25, and have added the following alias to my bash profile:

alias releasenotes="dnf updateinfo --refresh info `dnf check-update | cut -d '.' -f 1 | xargs` | less"

(I can't use straight-up dnf updateinfo info because of https://bugzilla.redhat.com/show_bug.cgi?id=1405191)

My alias works, but the command takes about 10 seconds to run, and since bash parses and validates all aliases when the profile is sourced, creating a new shell results in a 10-second hang. This is annoying.

Is there any way to make bash not try to parse and validate aliases--or just that one?

iLikeDirt

Posted 2017-03-05T14:15:11.530

Reputation: 283

Answers

9

My best guess is you should probably use single quotes around the alias definition.

I know that when using double quotes, shell variables are replaced with their content at the alias definition stage (like you said parsing and validating) and backticks or shell substitution like $(command).

A better explanation is in this Unix SE question!

If that doesn't help making the prompt load faster again, define a shell function instead of an alias.

edit: Don't forget to swap the cut argument to double-quotes like quixotic mentioned.

hyph

Posted 2017-03-05T14:15:11.530

Reputation: 341

That did it! You answered first, so you get the credit. – iLikeDirt – 2017-03-05T14:52:26.153

9

bash is interpreting your quoted string, and that interpretation executes the embedded dnf check-update command. This execution is what takes up the time during the alias definition, not the main dnf updateinfo command you're aliasing. Try a contrived example based on sleep and note how the alias itself takes 5 seconds:

alias sleep5="echo 'wake' ; `sleep 5` ; echo 'done'"

Use single-quotes to avoid the interpretation:

alias releasenotes='dnf updateinfo --refresh info `dnf check-update | cut -d "." -f 1 | xargs` | less'

Don't forget to swap the cut argument to double-quotes.

quixotic

Posted 2017-03-05T14:15:11.530

Reputation: 659