![](/img/trans.png)
[英]What does it mean in shell when we put a command inside dollar sign and parentheses: $(command)
[英]what does the dollar sign mean in the substitution line of bash command “rename”
我正在阅读有关重命名的内容,并遇到了以下示例,将文件扩展名从htm更改为html:
rename -v 's/\.htm$/\.html/' *.htm
它说: $
表示字符串的结尾。 \\.htm$
表示它将匹配.htm
而不匹配.html
。
我对这里使用$
感到有些困惑。 由于我们已经在命令行末尾指定了*.htm
,因此rename
只会选择htm文件(而不是html)。 那么为什么还需要使用$
呢? 换句话说,不使用$
怎么了?
锚$
匹配源文件名的结尾,并且在正则表达式中仍然需要它,并且也应转义点,否则abc.htm.htm
将重命名为abc.html.htm
而不是abc.htm.html
。
正确的命令是:
rename -v 's/\.htm$/.html/' *.htm
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.