What does `echo prefix = ~/.node >> ~/.npmrc` mean

2020-02-26 02:06发布

问题:

I'm reading this stackoverflow answer on running yo and npm without sudo by saving their results in ~/.node.

It uses echo prefix = ~/.node >> ~/.npmrc, and I'd like to know what each symbol means and how they work together in this case.

回答1:

echo prefix = ~/.node

This simply prints a string to standard output. The shell will expand ~ to the value of $HOME, so the string printed might be something like "prefix = /home/randwa1k" (without the quotation marks, of course).

... >> ~/.npmrc

This redirects the output of the echo command to the file ~/.npmrc, which expands to the same thing as $HOME/.npmrc. Using >> rather than > means that the output is appended to the end of the file.

So the command as a whole appends one line of text to a file called .npmrc in your home directory.

The effects of that change to the .npmrc file are going to depend on whatever programs read that file.



标签: linux shell unix