Shell script that accepts path names and creates all the components in that path names as directories

#!/bin/sh
if [ $# -ne 1 ]
then
echo " no arguments "
exit
fi
curdir=`pwd`
for dir in `echo $1 | tr '/' ' ' `

do
if [ -d $dir ]
then
echo "$dir exists under `pwd`"
cd $dir
else
mkdir $dir
echo "$dir created under `pwd`"
cd $dir
fi
done
cd $curdir
************************
Output: .
$chmod +x subdir.sh
$sh subdir.sh a/b/c/d
************************

Leave a Reply