【问题标题】:how to assign variable value in this touch command [duplicate]如何在此触摸命令中分配变量值[重复]
【发布时间】:2022-01-27 08:38:51
【问题描述】:

首先我想读取他想要创建的文件数

#!/bin/bash

touch file{0..$number}

我使用了这种语法,但输出如下

    file{0..number}      >> as example

【问题讨论】:

    标签: bash shell scripting touch brace-expansion


    【解决方案1】:

    bash 中,变量扩展发生在序列表达式扩展之后,因此您不能在序列表达式中使用变量。

    您需要使用类似 for 循环的东西:

    number=3
    for ((i=0; i<=number; i++))
    do
      touch file${i}
    done
    

    【讨论】:

    • 谢谢匹配
    猜你喜欢
    • 1970-01-01
    • 2017-08-12
    • 1970-01-01
    • 2014-07-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-08
    • 2010-12-15
    相关资源
    最近更新 更多