【问题标题】:error : "Home/files" unexpected in Bash/ksh programme错误:Bash/ksh 程序中出现“Home/files”意外
【发布时间】:2014-01-08 16:46:27
【问题描述】:

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

【问题讨论】:

  • 您可能需要&gt;&gt; "${indxFile}".txt,否则它将被每个内部while循环覆盖。
  • 条件通常是命令;结果取决于命令是成功还是失败。 [[ 是一个特例。 [[]] 之间的内容是表达式,而不是命令。

标签: bash shell unix scripting ksh


【解决方案1】:

您可以删除 if 中条件周围的 [[ ]]

if find /home/files  -name "${cobolFile}" | xargs grep $query ; then

【讨论】:

  • 这是否意味着 if 子句只有在 `"${cobolFile}" 中存在 $query 时才会评估为真
  • 在至少一个名为$cobolFile的文件中,是的
【解决方案2】:

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

#!/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

【讨论】:

    猜你喜欢
    • 2012-10-09
    • 2014-04-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-01
    • 2018-03-26
    相关资源
    最近更新 更多