[Wylug-help] bash help

Dan Chicot dan.chicot at gmail.com
Wed Feb 23 09:56:42 GMT 2005


Right, thanks very much.  What about the following: -

If I execute this script: -

1  #! /bin/bash
2  PPI="perl -ne 'print'"
3  echo $PPI
4  $PPI

I get the following output
perl -ne 'print'                  # from the echo
                                      # waits for input as expected ...

But 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

Thanks very much

Regards

Dan




On Wed, 23 Feb 2005 00:27:45 GMT, Smylers <Smylers at stripey.com> wrote:
> Dan Chicot writes:
>
> > 1   #! /bin/bash
> > 2   alias pp="perl"
> > 3   type pp
> > 4   pp
> >
> > pp is aliased to `perl'
> > ./script.sh: line 4: pp: command not found
> >
> > i.e why can type determin what pp yet the shell can't?
>
> bash(1), under 'ALIASES', says:
>
>   Aliases  are not expanded when the shell is not interactive, unless
>   the expand_aliases shell option is set using shopt.
>
> So if you insert this before line 4 then the pp will be found:
>
>   shopt -s expand_aliases
>
> That's possibly yet another reason why in general it makes more sense to
> use functions rather than aliases.
>
> It doesn't however explain why type gives the output it does; I'd
> suggest that's a bug, and that in a non-interactive shell when
> expand_aliases is unset type should ignore aliases.
>
> > And why does
> > source script.sh
> > work ok?
>
> Because source doesn't invoke a new shell process to run the script, but
> acts as though the script's contents had been typed into the current
> shell, which is interactive, and therefore expands aliases.
>
> Smylers
>
> _______________________________________________
> Wylug-help mailing list
> Wylug-help at wylug.org.uk
> http://list.wylug.org.uk/mailman/listinfo/wylug-help
>




More information about the Wylug-help mailing list