Weird input problem with shell scripts

Submitted by borwick on Fri, 2005-11-18 23:27.

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.

Trackback URL for this post:

http://lopsa.org/trackback/707

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Submitted by borwick on Thu, 2006-09-21 13:13.

RHEL 2.1:

sh-2.05$ rpm -q bash
bash-2.05-8.7
sh-2.05$ ./caller.sh
Got >weird<
sh-2.05$ cat caller.sh | sh
Got ><

RHEL 3:

bash$ rpm -q bash
bash-2.05b-41.7
bash$ ./caller.sh
Got >weird<
bash$ cat caller.sh | sh
Got >weird<