bug-bash
[Top][All Lists]
Advanced

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

[RFC] Support for POSIX "protected" word expansion mode


From: Thomas Fitzsimmons
Subject: [RFC] Support for POSIX "protected" word expansion mode
Date: 18 Jul 2002 12:34:16 -0400

Hello,

I'm implementing the wordexp function in newlib
(sources.redhat.com/newlib).  POSIX has this to say
about wordexp:

(From
http://www.opengroup.org/onlinepubs/007904975/functions/wordexp.html)
----------------------------------------------------------------------
While wordexp() could be implemented entirely as a library routine, it
is expected that most implementations run a shell in a subprocess to do
the expansion.

Two different approaches have been proposed for how the required
information might be presented to the shell and the results returned.
They are presented here as examples.

[first example extends echo's functionality]

Another proposal is to add the following options to sh:

-w wordlist

    This option provides a wordlist expansion service to applications.
The words in wordlist shall be expanded and the following written to
standard output:

       1.         The count of the number of words after expansion, in
decimal, followed by a null byte
       2.         The number of bytes needed to represent the expanded
words (not including null separators), in decimal, followed by a null
byte
       3.         The expanded words, each terminated by a null byte

    If an error is encountered during word expansion, sh exits with a
non-zero status after writing the former to report any words
successfully expanded

-P

Run in "protected" mode. If specified with the -w option, no command
substitution shall be performed.

With these options, wordexp() could be implemented fairly simply by
creating a subprocess using fork() and executing sh using the line:

execl(<shell path>, "sh", "-P", "-w", words, (char *)0);

after directing standard error to /dev/null.
----------------------------------------------------------------------

The --wordexp argument suits my needs in its current form, but I still
need to optionally prevent command substitution.

The attached patch, against bash-2.05b, adds support for a --protected
argument when bash is invoked.  If --protected is given along with
--wordexp, an attempt to perform command substitution will result in an
error, and bash will exit with an exit status of 1.  If --protected is
given without --wordexp, it is ignored.

Feedback welcome,
Tom 

-- 
Thomas Fitzsimmons
Red Hat Canada Limited        e-mail: fitzsim@redhat.com
2323 Yonge Street, Suite 300
Toronto, ON M4P2C9

Attachment: protected.diff
Description: Text Data


reply via email to

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