cat > caller.sh <<_CALLER_ #!/bin/bash echo "weird" | ./reader.sh _CALLER_ cat > reader.sh <<_READER_ : #! /bin/sh read TEST echo "Got >$TEST<" # quote is for 'cat > reader.sh' _READER_ chmod 755 caller.sh reader.sh ./caller.sh # prints 'Got >weird<' cat caller.sh | sh # prints 'Got ><'
The main issue is, what is that ‘:’ doing on the first line of
reader.sh? When it’s gone, things work correctly.