【发布时间】:2021-02-14 14:25:10
【问题描述】:
当我这样做时
ruby -e 'print "file: #{ARGF.filename}"' test1.adoc
它打印test1.adoc,但我正在寻找的是删除扩展名,所以我只得到test1。如果有
$ touch test1.adoc
$ ruby -e 'print "file: #{ARGF.filename}.sub('.adoc','')"' test1.adoc
Traceback (most recent call last):
1: from -e:1:in `<main>'
-e:1:in `filename': No such file or directory @ rb_sysopen - test1.adoc (Errno::ENOENT)
使用pop 很容易获得通用解决方案,但沿着这条路走下去会更加困难......
问题
谁能弄清楚如何在我的单行中删除.adoc?
【问题讨论】:
-
如果是
/foo/bar/test.adoc怎么办?你想要什么?