0

i have bash script(1.sh) which calls (2.sh) within a while loop. Execution stops after just one iteration. if i remove call to 2.sh it executes perfectly

my code 1.sh

while read -a A ; do
        echo "${GREEN}  Making production build for ${A[0]} ${NC}"
        # run build for each component
        ./2.sh ${A[0]} ${A[1]}

        if [[ $? -eq 1 ]]; then
            # create logs of error builds
            ERRORBUILDS+=${A[0]}" ,"

        fi
    done < $1   
  • Probably 2.sh reads from its stdin (that happens for instance if you call ssh without -n). You may want to read the content of $1 on a different file descriptor and close it within the loop. See examples at Why is using a shell loop to process text considered bad practice? – Stéphane Chazelas Feb 3 '17 at 11:43
  • @StéphaneChazelas sir, a correction in the code(build.sh to 2.sh). Could you please explicitly mention what changes i have to make. – user1869714 Feb 3 '17 at 11:48
  • It could be just a matter of redirecting 2.sh's stdin from /dev/null (add < /dev/null). The question would we why it reads from its stdin and what it expects to find there. – Stéphane Chazelas Feb 3 '17 at 12:00
  • @StéphaneChazelas Thank you for the solution. How to upvote your answer as the right answer – user1869714 Feb 3 '17 at 12:17
0
./2.sh < /dev/null ${A[0]} ${A[1]}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.