So after an uncomfortable number of hours of trying to do this, this is what I'm trying to do:
Write a bash shell script called direct.sh. This script will take an arbitrary number of command line arguments. Your script should create directories starting with the first argument, then the second directory inside the first one, and then the next one inside the second one, and so on.
For e.g. direct.sh dir1 dir2 dir3
should first create dir1, then create dir1/dir2, then finally create dir1/dir2/dir3
This is what I have done after 20 hours.
#!/bin/bash
for i in $@
do
mkdir -p $1/$i
done
I know its wrong. Please help.
for i in "$@"; do mkdir -p "$i" && cd "$i"; doneSince you are using individual arguments, you need to create a directory and then change to it before creating the next. Your other option is to build one string from all arguments with directory separators between the names and callmkdir -ponce. ALWAYS QUOTE YOUR VARIABLES.echo '$1/$i='"$1/$i"you would have understood your logic error. You can also useset -xbefore a line/block of code that is causing your problems so you can see what values variables are set too. Useset +xto turn it off later in the script. Good luck.