how to assign variable value in this touch command

507 views Asked by At

first i want to read number of files that he want to create it

#!/bin/bash

touch file{0..$number}

I trayed with this syntax but output is the following

    file{0..number}      >> as example
1

There are 1 answers

0
match On

In bash variable expansion happens after sequence expression expansion, so you can't use variables inside a sequence expression.

Instead you need to use something like a for loop:

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