help needed with creating challenging bash script with creating directories

Hi,

Can someone help me with creating a bash shell script.
I need to create a script that gets a positive number n as an argument.
The script must create n directories in the current directory with names like map_1, map_2 etcetera. Each directory must be contained within its predecessor. So map_1 contains map_2, map_2 contains map_3 and so forth.

Thanks for the help!

Looks like a homework question, so here's a hint: given the number "n", loop from 1 through n and create a string that represents the directory tree you want. Then use the "-p" option of "mkdir" command to create the directory tree.

Hope that helps,
tyler_durden

______________________________________________
"Only after disaster can we be resurrected."

n=1
while [ $n -le $1 ]
do
  dir=map_$n
  mkdir "$dir" && cd "$dir" || exit 1
  n=$(( $n + 1 ))
done

thanks tyler_durden & cfajohnson,

Can you also put in the comments tor this what does what?

Thanks

What part of it do you not understand?

a.sh

#! /bin/bash
i=1
pre=""
if [ $# -lt 1 ];then
echo "Usage a number char"
exit
else
while [ $i -le $1 ];do
  dir=${pre}${2-map}"_"$i
  mkdir $dir
  i=$(($i+1))
  pre=$dir"/"
done
fi
a.sh 4 map
map_1->map_2->map_3->map_4
# n is 1 by default 
n=1
# this is a loop where it actually says when n is less then 1 or on do something
while [ $n -le $1 ]
# this part I don't understand
do
  dir=map_$n
  mkdir "$dir" && cd "$dir" || exit 1
  n=$(( $n + 1 ))
done

$1 represents the input parameter(first parameter). So if you supply 4 when running the script, $1 will be 4. In that case, the while loop will be like
while [ 1 -le 4 ]...and then increment 1 by 1..till it reaches 4.

cheers,
Devaraj Takhellambam