Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have the following script code:

test.sh

echo "BEGIN"
while read CMD <&1; do
    [ -z "$CMD" ] && continue
    case "$CMD" in
    start)
            echo "get_start"
            ;;
    stop)
            echo "get_stop"
            ;;
    *)
            echo "get_uknown_command"
            ;;
    esac
    echo "END";
done

When I run it with:

$./test.sh <input.txt

I get my script locked

input.txt

start
stop
sthh

Why my script is locked? How I can fix that?

BTW: If I enter the data manually then the script will not lock.

share|improve this question

1 Answer

up vote 3 down vote accepted

What do you need the <&1 for? Remove it, and it works.

while read CMD; do

./test.sh  < input.txt 
BEGIN
get_start
END
get_stop
END
get_uknown_command
END
share|improve this answer
it works. thank you. Explaination why it does not work with 1? – MOHAMED yesterday
I was not careful when I used this code. <&1 means get from stdout. so my script is expecting input data from stdout and not form stdin. change it with <&0 will work. – MOHAMED yesterday
Thank you for the answer (+1) and accepted – MOHAMED yesterday

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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