shell 拷贝文件 (syntax error near unexpected token then问题和: command not found问题)

代码如下:

#!/bin/bash
echo "\n----------- 开始 --------------\n";
echo "\n—-----输入对应的环境 sit uat product—-----\n";
read -p "输入对应的环境 :" word

 source_path=XXXXX
 sit="sit"
 uat="uat"
 product="product"
echo $word
echo $uat
echo $sit
echo $product
echo "$word"="$sit"
if [ "$word" = "$sit" ];then
 des_path=XXXXX
elif [ "$word" = "$uat" ];then
 des_path=XXXXX
elif [ "$word" = "$product" ];then
 des_path=XXXXX
else 
   echo '输入环境有误';
   exit 0
fi

echo $des_path
echo $source_path

if [ -z "$des_path" ]; then
  echo '拷贝路径不存在'
  exit 0
else
    cp -R $des_path $source_path
fi

echo "\n----------- 完成 --------------\n"

注意事项;if [ “ w o r d " = " word" = " word"="sit” ] if语句的格式一定要规范
if空格[空格" w o r d " 空 格 = 空 格 " word"空格=空格" word"="sit"空格]
不然会报如下错误
syntax error near unexpected token then

15: [sit: command not found

你可能感兴趣的:(shell,文件拷贝,syntax,error,shell)