Bash is slow to start because of this line in .bashrc. What could cause this?

My .bashrc file contains a line to this effect:

alias prog="/path/to/script.sh $(find $(pwd) -name prog)"

When I comment out this line, Bash starts almost instantly when I open a new terminal. With this line, there is a 4-5 second delay before my cursor shows up.

Removing the nested commands $(pwd), etc. speeds it up again as well. Why is this happening? Can I still use nested commands somehow?


Because the command substitution is inside double-quotes, it is evaluated at the time that the command is defined. This causes find to look through your hard disk contents while .bashrc is running.

You, by contrast, appear to want it evaluated at the time of use. In that case, use single quotes:

alias prog='/path/to/script.sh $(find "$(pwd)" -name prog)'

Note that this alias will fail if any of the files found have whitespace in their names. To avoid that:

alias prog='find . -name prog -exec /path/to/script.sh {} +'

This latter form will work reliably for any kind of file name.