[Wylug-help] bash help

Towle, William william.towle at eldon.co.uk
Wed Feb 23 10:54:57 GMT 2005


> if I execute this script: -
> 1  #! /bin/bash
> 2  PPI="perl -ne 'print '"   # space after the word print
> 3  echo $PPI
> 4  $PPI
>
> I get the following
> perl -ne 'print '                # from the echo
> Can't find string terminator "'" anywhere before EOF at -e line 1.
>
> but if i type
> perl -ne 'print '
> (with the space) at the shell, perl waits for input

  The '-x' flag to the shell helps here, viz:
	[williamt at WILLIAMT:4] tmp $ cat foo
	#!/bin/sh -x

	PPI="perl -ne 'print '"
	echo PPI=$PPI
	$PPI

	[williamt at WILLIAMT:4] tmp $ ./foo
	+ PPI=perl -ne 'print '
	+ echo PPI=perl -ne ''\''print' ''\'''
	PPI=perl -ne 'print '
	+ perl -ne ''\''print' ''\'''
	Can't find string terminator "'" anywhere before EOF at -e line 1.

  (or you could just `sh -x ./foo` as a one-off).

  Anyway, give the shell perl -ne ''\''print' ''\''', and you'll see the
Same result as with the script ... I'd like to explain why that gets the
Result quoted above, but my head a splode.

  The alternative line
	eval $PPI
works.

HTH,
  Wills [edited by OutLook. Grr]





More information about the Wylug-help mailing list