[vox-tech] Shell Scripting Question

Ken Herron vox-tech@lists.lugod.org
Fri, 06 Jun 2003 11:11:16 -0700


--On Friday, June 06, 2003 10:37:04 -0700 Peter Jay Salzman <p@dirac.org> 
wrote:
> ever since i learned perl a year or two ago, i literally haven't touched
> shell scripting other than reading other people's scripts, so i'm a bit
> rusty, however, i think bourne style conditionals have the form:
>
> if [ condition ]
> then
> do something
> fi
>
> or:
>
> if test condition
> then
> do something
> fi

Any command (or pipeline) can follow the if. "test condition" and "[ 
condition ]" are just commands commonly used here. Something like this is 
perfectly legal:

	if mkdir -p $workingdir
	then
		cd $workdir
	else
		# mkdir would have printed an error message
		exit 1
	fi

Although my scripts generally create directories like this:

	[ -d $dir ] || mkdir -p $dir || exit 1

-- 
Kenneth Herron  Kherron@newsguy.com     916-366-7338