Could someone please explain this bash command?

假装没事ソ 提交于 2019-12-10 04:26:56

问题


From the website for RVM:

bash < <( curl https://rvm.io/releases/rvm-install-head )

What does that first less-than symbol do? What about the <(? I know this is a stupid question, but I'd love to understand this.


回答1:


Bash's process substitution replaces <( ... ) and >( ... ) with pipes from/to children. Hence the whole thing means "create a pipe from curl ..., and use it as stdin to bash".

Rather pointless, it would be better written

curl -L https://get.rvm.io | bash



回答2:


It's called process substitution. The ouput of the curl command is sent via an anonymous named pipe to the standard input of bash. Basically what that whole command is doing is executing what's retrieved by curl as a shell script.

I consider it risky, but some people seem to be OK with it. If you retrieve the file and run it in a separate step, though, you have an opportunity to inspect it first. Whatever you do, if you do it together don't run it as root or under sudo.



来源:https://stackoverflow.com/questions/5228150/could-someone-please-explain-this-bash-command

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!