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: L A Walsh
Subject: Re: aliases not supported by default in non-interactive mode...but POSIX required?
Date: Thu, 24 Aug 2017 19:59:59 -0700
User-agent: Thunderbird



Eric Blake wrote:
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.
My scripts were:

#!/bin/sh
shopt -s |grep expand

and

#!/bin/bash --posix
shopt -s |grep expand

On cygwin they show:
expand_aliases on

On linux they neither one shows expand_aliases as 'on'.

How does starting a script with "#!/bin/sh start a script in
bash 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.
So by default, break POSIX compatibility.  That doesn't sound useful.

Though when "-e" was changed in bash, both bash and posix mode were changed.
I asked why -e was not just changed in posix mode and why the old
behavior couldn't be retained in bash mode.  Was told the new POSIX standard
was desired.

So... why not with aliases as well.  With 2004 and 2008 standards, aliases
are standard.  If POSIX conformity is used to change historic "-e" behavior
(that used to only exist after a "simple [external] command" -- not
shell functions or complex ones as newer posix has changed things), then
seems aliases should conform as well.


Why do some people say aliases shouldn't be used, when they are
POSIX required for compatibility?
They exist solely for back-compat
----
   That isn't true.  Functions don't replace aliases for all purposes.

In almost every respect,
   "In almost every respect" != all, I.e. "in almost every respect" = "for
most purposes".
 shell functions are better
===
   not always.
 and more powerful than aliases.
   depends on definition of power.

  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
----
   That's another place where aliases can be used -- though not the one
I was thinking of.  Seems there are several places where they can
be used.  How is pointing to a one-sided argument of how bad something
can be on a random webpage not like a fake-news source?

   I used them to write "debugpush [dbgop]"/"debugpop" commands to be
used in scripts that would save current flags, apply selected
debug flags for a specific function/subroutine, then restore the flags
upon exit.  I also use them to increase legibility and maintainability
in my scripts -- neither having anything to do with "quoted*glop".

   But for those convinced aliases are limited to ugly hacks, I
am sure they'd never see other solutions offered by aliases that
functions either don't work with or would be much more complex to
create.





reply via email to

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