bug-bash
[Top][All Lists]
Advanced

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

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


From: Linda Walsh
Subject: doesn't bash do variable subst. or quote removal on function statement
Date: Sat, 09 Jan 2016 17:28:10 -0800
User-agent: Thunderbird



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 <address@hidden> 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.








reply via email to

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