简体   繁体   English

Unix通配符扩展/正则表达式

[英]Unix wildcard expansion/ regular expression

What will the below command do? 以下命令会做什么?

ls -l ${INPUT%.jnl}.jnl

$INPUT consists of some value. $INPUT由一些值组成。

${INPUT%.jnl} strips the shortest match of .jnl from the back of $INPUT . ${INPUT%.jnl}$INPUT的后面剥离最短的.jnl匹配项。

By then saying ${INPUT%.jnl}.jnl it looks like a way to make $INPUT consist in something + .jnl and prevent it being two times .jnl at the end, if $INPUT already contained that value. 然后说${INPUT%.jnl}.jnl似乎是一种使$INPUT包含某物+ .jnl的方法,如果$INPUT已经包含该值,则防止它最后是.jnl

So ls -l ${INPUT%.jnl}.jnl will perform a ls -l in the path/name indicated by $INPUT , making sure it ends with .jnl . 所以ls -l ${INPUT%.jnl}.jnl将在$INPUT指示的路径/名称中执行ls -l ,并确保其以.jnl

See some tests regarding the ${INPUT%.jnl} expression: 查看有关${INPUT%.jnl}表达式的一些测试:

$ var="hello.jnl.jnlbye"
$ echo ${var%.jnl}
hello.jnl.jnlbye    # as .jnl is not present in the back, nothing gets removed

$ var="hello.jnl.jnl"
$ echo ${var%.jnl}
hello.jnl           # it removed the last .jnl

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM