bug-bash
[Top][All Lists]
Advanced

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

Bug#741402: [bash] Shell functions definitions may require parentheses d


From: Filipus Klutiero
Subject: Bug#741402: [bash] Shell functions definitions may require parentheses despite function keyword
Date: Wed, 12 Mar 2014 01:57:19 -0400
User-agent: Mozilla/5.0 (X11; Linux i686 on x86_64; rv:17.0) Gecko/20131103 Icedove/17.0.10

Package: bash
Version: 4.3-2
Severity: minor
X-Debbugs-Cc: bug-bash@gnu.org

According to the manual, either the function keyword or parentheses should be 
sufficient to define a function:

Shell Function Definitions


 A shell function is an object that is called like a simple command and 
executes a compound command with a new set of positional parameters. Shell 
functions are declared as follows:
name () compound-command [redirection]
function name [()] compound-command [redirection]
 This defines a function named name. The reserved word function is optional. If 
the function reserved word is supplied, the parentheses are optional. The body 
of the function is the compound command compound-command  (see Compound 
Commands above). That command is usually a list of commands between { and }, 
but may be any command listed under Compound Commands above. compound-command 
is executed whenever name is specified as the name of a simple command. When in 
posix mode, name may not be the name of one of the POSIX special builtins. Any 
redirections (see REDIRECTION below) specified when a function is defined are 
performed when the function is executed. The exit status of a function 
definition is zero unless a syntax error occurs or a readonly function with the 
same name already exists. When executed, the exit status of a function is the 
exit status of the last command executed in the body. (See FUNCTIONS   below.)

The following definition should therefore be valid:
$ function bar (echo x)

...but it's not:
bash: syntax error near unexpected token `echo'

However, an identical function can be defined with the following definition:

$ function bar () (echo x)

I suspect this is an upstream bug.

--- System information. ---
Architecture: i386
Kernel: Linux 3.12-1-amd64

Debian Release: jessie/sid
990 testing debian.mirror.iweb.ca
500 unstable debian.mirror.iweb.ca
1 experimental ftp3.nrc.ca

--- Package information. ---
Depends (Version) | Installed
===========================-+-============
base-files (>= 2.1.12) | 7.2
debianutils (>= 2.15) | 4.4


Recommends (Version) | Installed
===================================-+-================
bash-completion (>= 20060301-0) | 1:2.1-2


Suggests (Version) | Installed
=======================-+-===========
bash-doc | 4.3-2

--
Filipus Klutiero
http://www.philippecloutier.com



reply via email to

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