bash - 从脚本变量中提取文件名
问题描述
我有一个批处理文件,例如
for f in bin/$1*.txt; do echo $f; done
我想只回显文件名 - 而不是 bin/temp.txt 或 temp.txt - 只是 temp。
如何从 $f 中提取文件名?
解决方案
如果后缀始终相同,则可以使用basename -s ".txt" $f
.
推荐阅读
- angular - 将 html 复制到剪贴板 (Angular)
- python - 即使文件存在,也找不到“Procfile”模板
- c# - TimerTrigger 立即执行,然后每 5 分钟执行一次
- java - 如何计算数组元素出现的次数
- php - 通过下拉列表从数据库中获取数据 | 拉拉维尔
- java - 在使用 Citrus 框架运行 rest api 测试时在 http() 上获取 NullPointerException
- git - 合并时自动与 master 同步开发
- swift - 运行 swift 模块时架构 x86_64 的未定义符号
- python - re.sub w/ 以不同数字结尾的子字符串
- python-3.x - 如何在不使用 javascript 方法 execute_script() 的情况下在 Python 中使用 selenium webdriver 滚动网页