First, I think your premise is flawed.
I want to create multiple directories using shell script without using loops using one line command
Why? You could make a loop with on one line if that were somehow important, but it really shouldn't be. If it's an assignment, be aware that your instructor is probably expecting an eval and (if they are any good) planning to screw you with it.
But there are still ways, if you allow for the fact that there's always a loop under the hood somewhere. For example -
seq "$2" "$3" | xargs -I@ mkdir "$1@"
That's "one line", though it could just as well be written as
seq "$2" "$3" |
xargs -I@ mkdir $1@
You could make it
xargs -I@ mkdir $1@ < <( seq "$2" "$3")
It's still executing a subshell, but it's "one line", and xargs & seq aren't exactly loops. This also doesn't use eval, so it's a lot safer.
Now the whole script is
#!/bin/bash
printf "%s\n" "$@"
prefix="$1"; shift # shift prefix off $@
xargs -I@ mkdir "${prefix}@" < <( seq -w "$@" ) # add leading zeros
And if I run it as
./tst 1 ";echo rm -fr ~;" 3
then it successfully fails without executing any malicious code.
$: ./tst 1 ";echo rm -fr ~;" 3
1
;echo rm -fr ~;
3
seq: invalid floating point argument: ‘;echo rm -fr ~;’
Try 'seq --help' for more information.
but with valid args it's good.
$: ./tst foo 9 12
foo
9
12
$: ls -ld ./foo*
drwxr-xr-x 1 paul 1049089 0 Jan 5 11:39 ./foo09
drwxr-xr-x 1 paul 1049089 0 Jan 5 11:39 ./foo10
drwxr-xr-x 1 paul 1049089 0 Jan 5 11:39 ./foo11
drwxr-xr-x 1 paul 1049089 0 Jan 5 11:39 ./foo12
{1..3}ain't support variables, just real numbers.