Use one loop to handle below code

 mknod /dev/vda b 253 0
 mknod /dev/vda1 b 253 1
 mknod /dev/vda2 b 253 2
 mknod /dev/vda3 b 253 3

I know below code is ease to handle, but I don't know above code

 mknod /dev/vda1 b 253 1
 mknod /dev/vda2 b 253 2
 mknod /dev/vda3 b 253 3

Using BASH:-

#!/bin/bash

for SEQ in {0..3}
do
        if [ $SEQ -eq 0 ]
        then
                mknod /dev/vda b 253 $SEQ
        else
                mknod /dev/vda${SEQ} b 253 ${SEQ}
        fi
done

Here is another way to do it that only uses shell behavior required by the POSIX standards:

#!/bin/ksh
i=0
while [ $i -le 3 ]
do      mknod /dev/vda${i#0} b 253 $i
        i=$((i + 1))
done

The construct for i in {0..3} is available in a some shells, but is an extension that is not specified by the standards.

1 Like

In reality you would do

mknod /dev/vda0 b 253 0

and finally create the shortcut

ln -s vda0 /dev/vda