简体   繁体   中英

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. 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"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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