[Wylug-help] bash help
Smylers
Smylers at stripey.com
Wed Feb 23 00:27:45 GMT 2005
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
More information about the Wylug-help
mailing list