在ACK-grep的安装脚本不熟悉shell语法 [英] Unfamiliar shell syntax in ack-grep install script

查看:284
本文介绍了在ACK-grep的安装脚本不熟悉shell语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从ACK安装页面(http://betterthangrep.com/install/)有一个班轮安装卷曲:

From the ack installation page (http://betterthangrep.com/install/) there is a one-liner installation with curl:

curl http://betterthangrep.com/ack-standalone > ~/bin/ack && chmod 0755 !#:3

据我所知,它是从网站上获取该文件并将其保存到〜/斌/ ACK后,设置权限,但到底是什么,去年部分(#!3)呢? (我不认识的语法和谷歌搜索没有取得任何有用的搜索结果)

I understand that it's getting the file from the website and saving it to ~/bin/ack, then setting permissions, but what does that last part ( !#:3 ) do ? (I do not recognize the syntax and Googling didn't yield any helpful results)

推荐答案

请参阅叫bash的人,特别是字标志款历史扩展部分。 #!3 指的是管道,这是第三个字(在你的例子)〜/斌/ ACK 。为了,命令的话是卷曲 0; http://betterthangrep.com/ack-standalone 1; > 2; 〜/斌/ ACK ,3; &放大器;&安培; 4; 搭配chmod ,5; 0755 ,6; #!3 ,7。
也就是说,#!3 是重复的文件名,而无需使用单独的变量或文字文本的方式。

See the section called HISTORY EXPANSION in man bash, particularly the Word Designators subsection. !#:3 refers to the third word of the pipe, which is (in your example) ~/bin/ack. In order, the words of the command are curl, 0; http://betterthangrep.com/ack-standalone, 1; >, 2; ~/bin/ack, 3; &&, 4; chmod, 5; 0755, 6; !#:3, 7. That is, !#:3 is a way to repeat the filename without using a separate variable or literal text.

对于有关的问题> 和空白,注意> 是一个元字符,这名男子bash的定义作为一个字符,不带引号的时候,分开的话。下列之一:| &安培; ; ()&下; >空间标签。所以空白不影响是否> 被视为一个令牌。但请注意,在下面的例子中,第一个 3 引述这样的bash不跨preT它作为一个 3&GT的一部分; 重定向。当输入了线,bash的呼应展开的线,然后执行它。

Regarding the question about > and whitespace, note that > is a metacharacter, which man bash defines as a "character that, when unquoted, separates words. One of the following: | & ; ( ) < > space tab". So whitespace does not affect whether > counts as a token. But note that in the following example, the first 3 is quoted so that bash doesn't interpret it as part of a 3> redirection. When the line was entered, bash echoed the expanded line and then executed it.

$ seq '3'>bbb;cat !#:3 !#:2 ccc; head !#:3 !#:8
seq '3'>bbb;cat bbb > ccc; head bbb ccc
==> bbb <==
1
2
3

==> ccc <==
1
2
3

这篇关于在ACK-grep的安装脚本不熟悉shell语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆