[PATCH] Ash support for replace and subsitution
Denys Vlasenko
vda.linux at googlemail.com
Mon Mar 24 21:56:32 UTC 2008
On Monday 24 March 2008 20:16, James Simmons wrote:
> > Well, maybe we should wait for a ruling by Denys or someone. I'd really
> > love to have a POSIX-standard shell in busybox, and I had this idea that
> > that was a design goal of ash.
>
> What is the goal for ash? That I don't know.
From the practical point-of-view, bbox need standard-compliant shell.
ash is (trying to be) such a shell. (Other two shells are far behind,
but they are much smaller, and work on NOMMU!)
Above standard-compliance, bbox needs a shell which emulates bash.
This is purely from practucal point-of-view: most Linux installations use
bash as the primary shell => most scripts are written for bash
(when they use non-standard bash-isms).
Trivial bashism example: "function" keyword.
Bashisms in ash can be guarded by ENABLE_FEATURE_BASH_COMPAT,
in order to make standard lawyer-esque people happier.
> > But I could be wrong. For example, the extended test notation [[ ... ]]
> > is not POSIX, but (according to your patch; I haven't checked it myself)
> > it's already supported.
SUSv3 says (see shell/susv3_doc.tar.bz2):
"The following words may be recognized as reserved words on some implementations
(when none of the characters are quoted), causing unspecified results:
[[ ]] function select"
man bash (bash 3.2) says:
[[ expression ]]
Return a status of 0 or 1 depending on the evaluation of the
conditional expression expression. Expressions are composed of
the primaries described below under CONDITIONAL EXPRESSIONS.
Word splitting and pathname expansion are not performed on the
words between the [[ and ]]; tilde expansion, parameter and
variable expansion, arithmetic expansion, command substitution,
process substitution, and quote removal are performed. Condi-
tional operators such as -f must be unquoted to be recognized as
primaries.
...
CONDITIONAL EXPRESSIONS
Conditional expressions are used by the [[ compound command and the
test and [ builtin commands to test file attributes and perform string
and arithmetic comparisons. Expressions are formed from the following
unary or binary primaries. If any file argument to one of the pri-
maries is of the form /dev/fd/n, then file descriptor n is checked. If
the file argument to one of the primaries is one of /dev/stdin,
/dev/stdout, or /dev/stderr, file descriptor 0, 1, or 2, respectively,
is checked.
Unless otherwise specified, primaries that operate on files follow sym-
bolic links and operate on the target of the link, rather than the link
itself.
-a file
True if file exists.
...
arg1 OP arg2
OP is one of -eq, -ne, -lt, -le, -gt, or -ge. These arithmetic
binary operators return true if arg1 is equal to, not equal to,
less than, less than or equal to, greater than, or greater than
or equal to arg2, respectively. Arg1 and arg2 may be positive
or negative integers.
So, it's indeed a bash'ism. (So far I don't see how it differs from "test
and "[". huh?)
> It is if you enable ENABLE_ASH_BUILTIN_TEST. Ash hs [[ and [ equivalent.
>
> > Also, it's not clear to me (again I haven't checked the code) what area
> > your second patch touches; the subject said "more test conditions" but
> > I've never seen a test(1) utility that supports <<=, etc. which seemed
> > to have already been supported by this applet.
I think we generally need to avoid inventing anything when we implement
well-known and documented things, it's enough trouble
trying to follow all other inventors! :)
Just imagine how bad it will be if "shell scripts which use
busybox ash's extensions" will appear!
I will review and reply to the patches separately.
--
vda
More information about the busybox
mailing list