bug-bash
[Top][All Lists]
Advanced

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

`declare -f' does not output the "function" keyword when required


From: Emanuele Torre
Subject: `declare -f' does not output the "function" keyword when required
Date: Sat, 3 Dec 2022 12:05:37 +0100

In Bash, it is possible to define functions that look like assignment
words using the function keyword:

    function a=2 { printf hi\\n ;}

When `declare -f' is used to output all the function definitions, bash
will not output that function definition with the "function" keyword,
generating invalid code:

    $ bash -c 'function a=2 { printf hi\\n ;}; declare -f'
    a=2 () 
    { 
        printf hi\\n
    }
    $ bash -c 'function a=2 { printf hi\\n ;}; declare -f' | bash -v
    a=2 () 
    bash: line 1: syntax error near unexpected token `('
    bash: line 1: `a=2 () '

Bash should either accept `a=2 () { printf hi\\n ;}' as a valid
definition like it accepts `function a=2 { printf hi\\n ;}' as valid, or
make `declare -f' output declarations that use the "function" keyword,
at least when necessary.

 emanuele6



reply via email to

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