Unix programming help

hey guys im trying to create a batch file that makes directories

i have this code atm

#!/bin/sh
echo "Please enter file name:"
read Filename
echo "enter number of files to be created "
read created
for (( i = 1; i < &created; 1++ ))
do
    mkdir $Filename$i
done

assume i enter "myfile" for file name and "6" for number of files

this suppose to make 6 files like the following

myfile 1
myfile 2
myfile 3
myfile 4
myfile 5
myfile 6

but its not doing anything..... can some1 plz point me into wright direction.

Thank!

&created == > $created
  1. Use $created instead of &created
  2. Use i++ instead of 1++
  3. Use <= instead of <
  4. Use touch instead of mkdir

The touch command creates 0 byte files if they do not yet exist. The mkdir command creates directories...

1 Like

Ah.. I am too behind in count :slight_smile:

hey guys thanks for the reply

I've changed what you both said but its still refuse to work

here is the changes i made

#!/bin/sh
echo "Please enter file name:"
read Filename
echo "enter number of files to be created "
read created
for (( i=1; i<= $created; i++ ))
do
    touch $Filename$i
done

is it because of the extra white spaces?

#!/bin/ksh
set -x
echo "Please enter file name:"
read Filename
echo "enter number of files to be created "
read created
i=1
while [ $i -le $created ]
do
    mkdir $Filename$i
        (( i++ ))
done

for loop has diferrent syntax as shown below

for i in 1 2 3 4
do
 some thing here
done

I think, sh doesn't support this type of for loop. use bash shell.

1 Like

i am trying to rewrite the code with while loop hopefully it will work

---------- Post updated at 06:55 AM ---------- Previous update was at 06:50 AM ----------

wow Thank you very much anchal_khare it worked like a charm!! with bash, oh man! I've spent 2hrs on this part :@:@:@ "dhanyavaad" man