bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: aliases not supported by default in non-interactive mode...but POSIX


From: Eric Blake
Subject: Re: aliases not supported by default in non-interactive mode...but POSIX required?
Date: Thu, 24 Aug 2017 21:22:48 -0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1

On 08/24/2017 08:49 PM, L A Walsh wrote:
> 
> However, in testing posix and non-posix modes  in bash 4.4.12, I don't
> see aliases being enabled in scripts.

That's what happens when you run your script in bash mode, rather than
POSIX mode.

> 
> To be POSIX conformant, wouldn't they have to be on?

Only if you are running bash in POSIX mode to begin with.  If you are
running in bash mode, then it is assumed that you will explicitly enable
alias expansion in your script, because you (should) know that bash's
defaults differ from the POSIX rules.  (And why does bash disable
aliases by default? Because it helps remind people that shell functions
are better than aliases)

> 
> Why do some people say aliases shouldn't be used, when they are
> POSIX required for compatibility?

They exist solely for back-compat (for the same reason that 'set -e'
exists), and have very non-intuitive behavior on when they take effect
(for example, wrapping your entire script in {} can effectively bypass
any aliases attempted within your script - because aliases are expanded
at parse time rather than execution time but you have to parse to the
closing }). In almost every respect, shell functions are better and more
powerful than aliases.  And the few hacks where aliases can be used to
do things that shell functions cannot do, like temporarily disabling
globbing so that you can write 'find raw*glob' instead of 'find
"quoted*glob"', are so gross that I can only point you to the web page
discussing how gross they are:
https://www.chiark.greenend.org.uk/~sgtatham/aliases.html

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]