使用 touch 命令创建多个文件的时候, 怎么带入参数?

King6860 2017-04-05 11:35:54


背景: 有个配置文件 nba.txt , 里面记录了
startIndex=1
endIndex=20
两行文本。 现在要根据该文件的配置信息来创建文件,我使用 touch命令创建20个。

我的脚本如下:
$ source nba.txt
$ touch test-{$startIndex..$endIndex}.txt

运行了上述代码后, 只创建了 test-{1..20}.txt这个文件。 请问怎么把参数给带入到脚本变量中。
...全文
588 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
ECNU_Cheng 2021-04-19
  • 打赏
  • 举报
回复
#! /bin/bash for i in `seq -w 100 419` do mkdir $i cd $i touch ${i}_0.bmp touch ${i}_1.bmp touch ${i}_2.bmp touch ${i}_3.bmp touch ${i}_4.bmp cd .. done
nswcfd 2017-04-06
  • 打赏
  • 举报
回复
跟bash解析和展开的顺序有关系。
The order of expansions is: brace expansion, tilde expansion, parameter, variable and arithmetic expansion and command ubstitution (done in a left-to-right fashion), word splitting, and pathname expansion.
先做{}展开,然后再进行参数替换。
  • 打赏
  • 举报
回复
用for循环~~
King6860 2017-04-05
  • 打赏
  • 举报
回复
若直接使用 touch test-{1..20}.txt 是可以创建的, 但为什么使用带变量的 脚本,却无法创建呢??

23,217

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧