简体   繁体   English

Unix Shell 脚本

[英]Unix Shell Scripting

I have seen the concept of process substitution.我已经看到了进程替换的概念。 But the following code still give me the syntax error但是下面的代码仍然给我语法错误

script.sh: syntax error at line 44: `<' unexpected

script.sh: syntax error at line 44: `<' unexpected

Here is the code:这是代码:

#!/bin/bash

count=1

FILENAME=$1

JUDGE="YATES"

echo "VALUE OF JUDGE IS $JUDGE"

STATUS=""

#The file is read using while loop , file being supplied as cmd line arg , file simply contains the list of courts . 

#cat $FILENAME | while read LINE

while read LINE

do

#Selecting the filepath here $LINE contains the court every time it iterates    

FILEPATH=/elFZ/dZcollection/$LINE/DETER_JUDGE

#Checking whether the DETER_JUDGE exists or not ,     
cat $FILEPATH >> yatisawhney.txt 2>> yati_errors.txt


#if the DETER_JUDGE file exists then 
if [ $? = 0 ]
    then    

    echo "INSIDE IF"

    STATUS="Yes"

    #cat $FILEPATH | while read -r JUDGELINE

    #open the DETER JUDGE file and read the values and updating the JUDGE variable. 

    while read  JUDGELINE   

    do  

    line_length=$JUDGELINE


    JUDGE=$JUDGE$line_length"||||||"    

    #JUDGE=1000

    done < < ( $FILEPATH )

    echo "Value of judge is $JUDGE"

else
    FILEPATH="N.A."

    STATUS="No"

    JUDGE="N.A."

fi

#here I am not getting the updated value

echo $JUDGE >> JUDGE_NAME

echo $count","$LINE","$STATUS","$JUDGE","$FILEPATH >> judgeData.csv

count=`expr "$count" + 1`

JUDGE=""

done < < ( $FILENAME )

I am unable to the fetch the values from the inner while loop.我无法从内部 while 循环中获取值。 However I am able to fetch them inside the loop, once I get outside the values get lost.但是我能够在循环内获取它们,一旦我离开值就会丢失。

The process substitution uses the <(...) construct, there should be no space between the < and the left parenthesis.进程替换使用<(...)构造, <和左括号之间不应有空格。

To read from a file, you don't need process substitution at all:要从文件中读取,您根本不需要进程替换:

done < "$FILENAME"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM