How do I stop a command inside an alias from running when .bashrc is sourced?

My issue: whenever I open a new terminal window, ~/.bashrc is sourced and the yolk -U | awk '{print $1}' yolk -U | awk '{print $1}' portion of this alias described below is executed.

This causes most of my new windows to have the phrase "No new packages at the Cheese Shop" at the top, and it prevents the prompt from actually displaying until the command has finished. This can take a not-insignificant number of seconds on a regular basis.

My question: How can I stop that? I don't want this to run until I use the alias explicitly.

Inside my ~/.bashrc file, I have the following alias :

alias pipup="sudo pip install -U `yolk -U | awk '{print $1}'`"

I use this outside of my virtualenv to update the global packages like pip , setuptools , virtualenv , virtualenvwrapper , yolk , some linters, and a couple cli utilities.

The alias itself works fine, and the command runs as expected.

OS X 10.9.1 (although this "problem" has existed for me since 10.6) bash 3.2.51


The alias needs to be in single quotes.

alias pipup='sudo pip install -U `yolk -U | awk "{print $1}"`'

What you report as "working" has been doing the wrong thing all along: It runs yolk when you log in, and the alias ends up looking something like

alias pipup='sudo pip install -U fnord'

which you should be able to verify by examining the output from alias pipup .

The shell's quoting facilities are often poorly understood, although the system isn't very complex or surprising. See eg http://mywiki.wooledge.org/Quotes

As noted by @devnull in a comment, a shell function would be a better solution overall. Aliases are historical deadweight.

链接地址: http://www.djcxy.com/p/26378.html

上一篇: 我如何检查OS X中的sed版本?

下一篇: .bashrc源代码时如何停止运行别名中的命令?