- 论坛徽章:
- 0
|
新人学习shell,写了一个创建指定目录,并将某个目录下的指定文件拷贝到该目录下的脚本,不过运行时出现如下错误
copy_file.sh: line 20: syntax error near unexpected token `$is_postive'
copy_file.sh: line 20: ` case $is_postive in'
这第20行这个变量is_postive到底哪儿有问题,各位大神帮忙看下哈
#!/bin/sh
input_num(){
if [ $# -ne 1 ]
then
echo "arguments error"
fi
num=""
while :
do
read _num
is_postive=`echo ${_num}|sed 's/[0-9]//g'|awk '{print length($0)}'`
if [ $_num -ne 0 ]
then
case "$is_postive" in
1)
echo "your input is not a positive integer,please input a positive integer";num="";;
case "$is_postive" in
0)
num=${_num};break;;
*)
echo "unknown error,please input a positive integer again";num="";;
esac
else
echo "your input number is zero,please input a positive integer"
fi
done
export num
return 0
}
input_num "please input the counts of dictionaries you want to create and copy"
if [ -d $HOME/aa ]
then
rm -rf $HOME/aa
fi
count="0"
while [ $count -lt $num ]
do
count =`echo $((count + 1))`
mkdir -p $HOME/aa/bb/ch${count} > /dev/null 2>&1
if [ $? -ne 0 ]
then echo "create dictionary ch${count} failed,please check it";continue
fi
for i in chm doc xls html
do
if [ -f $HOME/*.${i} ] && [ -d $HOME/aa/bb/ch${count} ]
then
cp $HOME/*.${i} $HOME/aa/bb/ch${count} > dev/null 2>&1
if [ $? -ne 0 ]
then
echo "copy $HOME/*.${i} to $HOME/aa/bb/ch${count} failed"
else
echo "copy ${i} to ch${count} successful"
fi
elif [ ! -f $HOME/*.${i} ]
then
echo "the ${i} files are not exit"
elif [ ! -d $HOME/aa/bb/ch${count} ]
then
echo "$HOME/aa/bb/ch${count} is not exit"
else
echo "unkown error"
fi
done
done |
|