红联Linux门户
Linux帮助

Solaris下shell的if语句问题

发布时间:2010-11-25 14:47:57来源:红联作者:meycine
在Solaris创建目录的shell脚本:
#!/bin/sh
#ifmkdir
#parameter is passed as $1 but reassigned to DIRECTORY
DIRECTORY=$1
#is the string empty??
if [ "$DIRECTORY" = "" ]
then
echo "Usage: `basename $0` directory to create" >&2
exit 1
fi

if[ ! -d $DIRECTORY ]
then
echo "The directory does't exist" #14行
echo -n "Create it now? [y..n] :"
read ANS
if [ "$ANS" = "y" || "$ANS" = "Y" ]
then
echo "creating now"
#create directory and send all output to /dev/null
mkdir $DIRECTORY >/dev/null 2>&1
if [ $? != 0 ]
then
echo "Errors creating the directory $DIRECTORY" >&2
exit 1
fi
fi
fi

执行该脚本:./ifmkdir.sh kkk
报错如下:
./ifmkdir.sh: if[: 没找到
./ifmkdir.sh: 语法错误在14行:`then' 非期望的

请各位大侠帮帮忙,我刚学习shell,希望大家帮忙指点一下,谢谢!!!
文章评论

共有 2 条评论

  1. mg271603433 于 2011-01-05 18:33:48发表:

    顶一个。顶一个。

  2. mg271603433 于 2011-01-05 18:33:47发表:

    顶一个。顶一个。