[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Edlug Archive Jan 2004 ]

Re: [edlug] bash script help needed

>> MYDIR = ~user/dir
>> mkdir $MYDIR/some/other/dir
> if your mkdir is a recent GNU version you can do this:
> ---
> MYDIR = ~user/dir
> mkdir -p $MYDIR/some/other/dir
> ---
> but don't foget to check all your exit values. :-)

No, that won't work!  It has to be 
MYDIR=~user/dir	# no whitespace
mkdir -p $MYDIR/some/other/dir
And if you aren't reusing the variable later it's a waste of effort:
mkdir -p ~user/dir/some/other/dir # will do
>> if !exists some/dir
>>   mkdir some/dir
>> endif (if needed)
> [ ! -d some/dir ] && mkdir -p some/dir

Redundant, since mkdir -p wouldn't mind if there _was_ something
already there - all you need is plain
mkdir -p some/dir 
However, if there's a possibility you need to handle obstacles that
_aren't_ directories then you need something more complex, such as
if	[ -L some/dir ]	# nb dangling symlinks fail [ -e ]
then	echo "there's a symlink in the way"
elif	[ -d some/dir ]
then	echo "there's already a directory there"
elif	[ -e some/dir ]
then	echo "there's a file in the way"
else	echo "whoop-ti-doo"
	mkdir -p some/dir
Ankh kak! (Ancient Egyptian blessing)
You can find the EdLUG mailing list FAQ list at:

This archive is kept by wibble@morpheux.org.DONTSPAMME