Re: aliases v. functions; command extension? (-f & -F)?

2016-01-09 Thread Piotr Grzybowski
On Sat, Jan 9, 2016 at 8:12 PM, Reuti  wrote:
>
> AFAICS putting the name in quotes (single or double) will prefer the function 
> over the alias, but it will fall back to a command if there is no function.
>
> 'P' params

 if Linda is ok with it, I will not argue, I would prefer an explicit
way to call what I want.

>
> Does:
>
> type - a P
>
> list them in order? It seems always to be in the order alias - function - 
> command.

 slightly forgot about that ;-) I am not sure if it removes all doubts
about what will be called though.

cheers,
pg



Re: 'official function declaration format' doesn't work if alias defined

2016-01-09 Thread Eric Cook
In mksh, ksh93, zsh and maybe others, you can use quotes to suppress alias 
expansions during definition just like you would a simple command; 
unfortunately bash deems it a invalid identifier.




Re: aliases v. functions; command extension? (-f & -F)?

2016-01-09 Thread Reuti

Am 08.01.2016 um 21:36 schrieb Piotr Grzybowski:

> hello Linda,
> 
> On Fri, Jan 8, 2016 at 9:14 PM, Linda Walsh  wrote:
>> 
>> For what it's worth, It might be useful to have something like
>> 'command' [..]
> 
> that would be useful, a keyword like:
> 
> function p params;

AFAICS putting the name in quotes (single or double) will prefer the function 
over the alias, but it will fall back to a command if there is no function.

'P' params


> that always calls function no matter what. maybe best would be to have
> something like:
> 
> run -f fname params # if (f=find_function("fname"))!=null executes f else 
> error
> run -c cname params # same as command cname params
> same with alias?
> 
> maybe together with some general "whatis" mechanism, that would give
> information about a symbol, its definitions, and the order in which
> they are to be resolved.

Does:

type - a P

list them in order? It seems always to be in the order alias - function - 
command.

-- Reuti




doesn't bash do variable subst. or quote removal on function statement

2016-01-09 Thread Linda Walsh



Reuti wrote:

Am 08.01.2016 um 21:36 schrieb Piotr Grzybowski:

  

hello Linda,

On Fri, Jan 8, 2016 at 9:14 PM, Linda Walsh  wrote:


For what it's worth, It might be useful to have something like
'command' [..]
  

that would be useful, a keyword like:

function p params;


But 'function p'... is already a lead-in to a function definition, i.e:
function xyz { :; }  #(create function foo)


AFAICS putting the name in quotes (single or double) will prefer the function 
over the alias, but it will fall back to a command if there is no function.

'P' params
  


   Not in a function definition (i.e. this is broken AFAIAC in bash).
I.e.

 'func' () { :; }

-bash: `'func'': not a valid identifier

 function 'func' () { : ; }

-bash: `'func'': not a valid identifier

 function "func" () { :; }

-bash: `"func"': not a valid identifier
---
That's weird.  while, _maybe_ I could see the 1st one not working
if looking for a bash keyword, but the 2nd & third forms seems odd.
I thought variable substitution and quote-removal was supposed
to happen before the statement is executed ??

I.e.: this _seems_ broken:


 shopt -s expand_aliases; alias my=declare
 declare fn=myfunc## function name in variable 

doesn't work

 function $fn { echo $fn ; }

-bash: `$fn': not a valid identifier

my -pf myfunc

-bash: declare: myfunc: not found


 def="function $fn () { echo $fn ; }"  ## but same statement, eval'd works
 eval $def   
 my -f myfunc

myfunc ()
{
   echo myfunc
}

I.e. while having the function name in a variable doesn't work
interactively, it does work when used with eval.