错误:Bash / ksh程序中出现“Home / files”意外

时间:2014-01-08 16:46:27

标签: bash shell unix scripting ksh

if子句中出现错误,其中包含:

/home/files unexpected. 

我不知道出了什么问题,这是KornShell(ksh)脚本。

#!/bin/ksh
selectPart="SELECT."
filePart="_FILE"
while read -r indxFile; do
  while read -r cobolFile; do
    query=$selectPart"${indxFile}"$filePart
    if [[ find /home/files  -name "${cobolFile}" | xargs grep $query ]];then
        while read -r scriptFile;do
          print "${scriptFile}"
        done < listScripts.txt > "${indxFile}".txt
    fi

  done < cobolNames.txt
done < indexedFiles.txt

2 个答案:

答案 0 :(得分:1)

您可以删除if:

中条件周围的[[ ]]
if find /home/files  -name "${cobolFile}" | xargs grep $query ; then

答案 1 :(得分:0)

请提供您的任务的更多详细信息。以下是相关代码的更新。

#!/bin/ksh
selectPart="SELECT."
filePart="_FILE"
while read -r indxFile; do
  while read -r cobolFile; do
    query=$selectPart"${indxFile}"$filePart
    findResult=find /home/files -name "${cobolFile}" | xargs grep $query
    echo "findResult: ${findResult}"
    if  [[${findResult} -eq 0]]; then
        while read -r scriptFile;do
          print "${scriptFile}"
        done < listScripts.txt >> "${indxFile}".txt
    fi
    done < cobolNames.txt
done < indexedFiles.txt