0

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.

1 Answer 1

3

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
Sign up to request clarification or add additional context in comments.

2 Comments

it works. thank you. Explaination why it does not work with 1?
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.