[ale] bash/korm mkdirs
Oysgelt, Moisey G [GMG]
moisey.g.oysgelt at mail.sprint.com
Thu Sep 11 14:28:44 EDT 2003
I decided to write a shell function mkdirs.
To create multiple level directories in on pass.
I found this very useful, and I could not goggled it.
so I used cigwin to wrote next script
----------------
#!/usr/bin/bash
# set -x trace
dir=""
function _m_d()
{
if [[ -n $1 ]] ; then
dir="$dir$1"
if test ! -d $dir ; then
mkdir $dir
fi
dir="$dir/"
fi
}
function _mkdirs()
{
dir=""
bigdir=$1
bigdir=`echo $1 | sed 's/ /\\\\ /g'`
sdir=$(echo $bigdir | awk -F "/" '{print $1}')
if [[ -n $sdir ]] ; then
_m_d $sdir
else
return
fi
sdir=$(echo $bigdir | awk -F "/" '{print $2}')
if [[ -n $sdir ]] ; then
_m_d $sdir
else
return
fi
sdir=$(echo $bigdir | awk -F "/" '{print $3}')
if [[ -n $sdir ]] ; then
_m_d $sdir
else
return
fi
sdir=$(echo $bigdir | awk -F "/" '{print $4}')
if [[ -n $sdir ]] ; then
_m_d $sdir
else
return
fi
if [[ -n $sdir ]] ; then
_m_d $sdir
else
return
fi
## and so on up to 20
}
_mkdirs "a/b/c/da/b/c/da/b/c/d"
----------------
***********************
I wanted to make a loop
like
for x:=1 to 20 do
stmp="echo $bigdir | awk -F "/" '{print \$$x}'"
sdir=`$stmp`
if [[ -n $sdir ]] ; then
_m_d $sdir
else
return
fi
done
****************
but this did not fly
What wrong did I do. Do I miss something fundamental in korn.
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.516 / Virus Database: 313 - Release Date: 9/1/2003
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Ale
mailing list