[oclug] How do I input in a (bash) shell script

Joe Burpee jeb at burkby.com
Sun Feb 25 01:23:58 EST 2001


Josh Diakun wrote:
> Let me get this straight you want to enter a string like... "hey does this
> work" ...into a variable...what I posted should do so.

OK, but it don't think it will preserve leading or trailing whitespace. 
If that is a concern, it is safer to use `read' with no arguments.  The
complete input line then should be in "$REPLY":
  read
  foo="$REPLY"
  echo "Foo text: $foo."

Alternatively, you might fiddle (carefully) with $IFS; e.g. `IFS=' will
remove any special treatment of whitespace.  Another solution would be
to avoid shell conventions entirely and read thru an external program
like:
  foo=`head -1`

The original question was on how to convert Perl stuff to bash.  To
illustrate, an equivalent of
  while (<>) { print }
could be
  while read; do echo "$REPLY"; done

This kind of thing looks ok I think; but still, if it ain't broke don't
fix it.  I don't buy the nonsense that there's something fundamentally
wrong with Perl (or bash for that matter).

C, on the other hand, is complete crap.  ;-)

Joe



More information about the OCLUG mailing list